//In case of hooks, you should use useEffect hook.
const [fruit, setFruit] = useState('');
setFruit('Apple');
useEffect(() => {
console.log('Fruit', fruit);
}, [fruit])
this.setState({pencil:!this.state.pencil}, myFunction)
myFunction = () => {
this.props.updateItem(this.state)
}
//if some of your code depends on that state update you can use a useeffect like this
useEffect(() => {
if (currentProgress[index].progress === 100) {
GoBack()
}
}, [currentProgress])