can you help me cancel the subscriptions in this case?
const Main = () => {
const [ toggle, setToggle] = useState(false)
return (
<React.Fragment>
{toggle && <Child />}
<button onClick={() => setShow(prevState => !prevState)}>toggle</button>
</React.Fragment>
)
}
const Child = () => {
const [ success, setSuccess] = useState(false)
const createUser = () => {
return createUserInTheDatabase()
.then(() => setSuccess(true))
}
return (
<React.Fragment>
{success && <p>user created<p>}
<button onClick={() => createUser()}>create user</button>
<React.Fragment>
)
}
I get the error when I click the toggle button and the createUser function in the Child component didn´t finish the execution. not exactly what to do in the useEffect cleanup function.