/react-hooks-demo

Code containing 2 code versions, before and after using hooks

Primary LanguageJavaScript

React-Hooks-Demo

This repo contains code from the blog post 5 Ways to convert react class components to functional components with hooks

The blog posts discuses how to refactor 5 types of React component classes to have the same behavior with Hooks

In class we will mount the component to App, view the code and discuss how it works

Scenario 1 : Class without state or lifecycle methods

Scenario 2 : Class with state

Scenario 3 : Class with multiple state properties

Scenario 4 : Class with state and componentDidMount and componentWillUnmount

Scenario 5 : Class with state, componentDidMount and componentDidUpdate

Next we will go to another blog Why react hooks and how did we get here to understand

  • The benefits of using Hooks as opposed to classes in your new components.
  • Some rules we need to keep in mind when using Hooks

The last blog article Simple code reuse with react hooks is another example of how to build your own custom hook