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 email@example.com to let us know what you think.
Facebook have moved to promote the use of Functional Components and to do this React needed a mechanism to add State to them and also to support other features. One of the main objectives was to make any new way of creating components backwards compatible. React version 16.8 is the one with Hooks, but what are Hooks, Hooks let you literally hook into React's state and lifecycle features. In terms of Functional Components, this solved a raft of problems encountered by the React team. These being the reuse of stateful logic between components, the splitting of complex components into smaller functions based on their relationships and the simplification of code syntax. Class components being simplified to functional components is much like syntax and code required. It makes the building optimization process better as there's less to transpile. To re-iterate, there is no need to rewrite class components in applications as functions, as class components will always be valid. It's just recommended that new components should be built as functions using Hooks. State Hooks are available in React and what do they do, there are a few Hooks built into the library already. If you've covered the content on 'Thinking in React', we use a State Hook to allow functional components to have state. Another hook that is commonly used out of the box, is the Effect Hook. The Effect Hook is the one that allows us to hook into the lifecycle methods that we would see in a class component to perform side effects, hence its name. We'll go into more detail about this hook later. React has some other Hooks and we'll look into the useContext and useReducer Hooks when we investigate other state management techniques. There's also useMemo, useCallback, useRef, useImperativeHandle, useLayoutEffect and useDebugValue. The last one, useDebugValue is perhaps the most interesting for developers as it lets us display a label for Custom Hooks in the DevTools and talking of Custom Hooks, we aren't limited to those Hooks provided by React. We can create Custom Hooks to do almost anything we need them to, as long as we follow the rules for Hooks, and the steps for creating our own hook, as outlined in React's official documentation.
About the Author