In case of hooks, you should use useEffect hook.
const [fruit, setFruit] = useState('');
setFruit('Apple');
useEffect(() => {
console.log('Fruit', fruit);
}, [fruit])
setChat(oldChats =>[data, ...oldChats])
const [state = initialValue,setState] = useState()
const [state = initialValue,setState] = useState()