https://chatgpt.com/share/690e46cc-2654-8007-8f8b-e1f833521253

Note: As a rule of thumb, in React, if the value of a state is dependent on another state, then the dependent state should not be declared as a state at all. Because it is more error prone because of out of sync state updation. In such cases, just compute the dependent state in a variable or on the go from the independent state.

useEffect(() => {
	async function foo () {
		// do async task
	}
	foo()
	return () => { // cleanup logic }
}, [dep])