Performing a Task at the Mount
Explore how to handle tasks during the mounting phase of React function components. Understand initializing state, fetching data asynchronously from an API, and updating the UI using custom state management functions for dynamic content rendering.
We'll cover the following...
Mount and un-mount dynamic component
Components
Let's say a count value needs to be fetched from an online service called /giveMeANumber. When this fetch returns successfully, we would like to reflect the change to the screen:
fetch('/giveMeANumber').then(res => {// Once the data is successfully retrieved, render the 'Title' componentReactDOM.render(<Title />, rootEl);})
The code above represents what we'd like ...