I don't quite understand what "Mount" means in React and when useEffect and clean up function are triggered.
In the example below. It appears that the useToggle hook is "bonded" (the correct term?) to the App component, and every time variable isOn gets updated, the bonded App component gets re-rendered. However, the cleanup function gets called as well. I tried to compare it to React's class component's life cycle.
Correct me if my understanding is wrong.
Reference: Diagram from Trey Huffine with edits
useEffect(updateFunc => cleanupFunc, [dependency array]) on Life Cycle

const { useReducer, useEffect } = React;
// Purposefully moved the toggle logic to a custom hook for understanding
function useToggle(inital) {
const [isOn, toggle] = useReducer(isOn => !isOn, inital);
useEffect(()=>{
console.log("update function called");
return () => console.log("cleanup function called");
}, [isOn])
return [isOn, toggle];
}
function App() {
const [isOn, toggle] = useToggle(false);
return (
<div>
<input type='checkbox' value={isOn} onClick={toggle}/>
Click Me
</div>
)
}
ReactDOM.render(<App/>, document.querySelector('.App'))
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.8.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.8.3/umd/react-dom.production.min.js"></script>
<div class='App'/>