79651523

Date: 2025-06-03 15:35:00
Score: 1.5
Natty:
Report link

Thank you @jonsharpe!

Using an updater function to set the state fixes it.

const [items, setItems] = useState<Item[]>([])

const createItem = useCallback(async (item: Item) => {
    info("posting new Item");

    fetch(`${API_SERVER}/CreateItem`, {"POST", body: item})
        .then(response => setItems(items => [...items, response]));
}, [items]);

Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Has code block (-0.5):
  • User mentioned (1): @jonsharpe
  • Self-answer (0.5):
Posted by: Brian