Introduction to Hooks
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.
- [Narrator] Facebook have moved to promote the use of function 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 state and lifecycle features. In terms of function components, this solved the rafter 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 transpire. To reiterate, 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. SWAT hooks are available in react and what do they do. There were a few hooks built into the library already. If you've covered the content on thinking in react we use the state to allow function 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 use content and use reducer hooks, when we investigate other state management techniques. There's also use Memo, use Callback, use ref, use imperative handle, use layout effect and use debug value. The last one, use debug value is perhaps the most interesting for developers as it lets us display label for custom hooks in the dev tools. 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 reacts official documentation.
Ed is an Outstanding Trainer in Software Development, with a passion for technology and its uses and holding more than 10 years’ experience.
Ed is responsible for delivering QA’s Programming Foundations course using the Eclipse IDE. His skillset extends into the DevOps sphere, where he is able to deliver courses based around Agile/Scrum practices, version control, and CI/CD.