The course is part of this learning path
This module looks at how to work with External Data in React. You’ll be looking at Class Components, Effect Hooks, and how to handle data.
The objectives of this module are to provide you with an understanding of:
- The component lifecycle
- Hooks in React
- How to create restful services
- How to use an Effect Dependency Array
- How to hand errors in data requests
- How to send data
This learning path is aimed at all who wish to learn how to use the ReactJS framework.
We welcome all feedback and suggestions - please contact us at firstname.lastname@example.org to let us know what you think.
The use effect hook is there for state. But what about lifecycle methods? How do we hook into the life cycle methods like ComponentDidMount, ComponentDidUpdate and ComponentWillUnmount? These lifecycle methods often perform side effects that updates stating components and make requests for data. Step up the effect hook, use effect. This effectively replaces all three of those lifecycle methods in one callback function. The use effect hook runs after React flushes changes to the DOM after every render including after the initial one. It takes an argument of a callback function to execute when use effect is run and optionally an array of dependencies for the effect. We'll come back to this array later. We declare use effect inside the component's function body so it and its callback, both have access to the components props and state. Use effect callback can update state by calling the state of data functions. The main body of the callback function replaces ComponentDidMount and ComponentDidUpdate lifecycle methods found in class components. Cleanup is also performed by the use effect hook by adding a return to its callback. The return itself should be a callback that performs the required tasks. We can have more than one effect hook in a component.