JD
Sign in

Getting Started with React Hooks

React Hooks were introduced in React 16.8 and have completely changed the way we write functional components. Previously you needed class components for state and lifecycle methods, but now you can do all of this with functions.

useState is the most commonly used hook. You call it with an initial value and get back an array containing the current value and a setter function. useEffect replaces componentDidMount, componentDidUpdate and componentWillUnmount in one elegant API.

In this article I show how I use hooks in my projects and what pitfalls I ran into along the way.