Johnson Lai avatar

Testing latest React API: React Hook

superoo7

Published: 11 Jan 2019 โ€บ Updated: 11 Jan 2019Testing latest React API: React Hook

Testing latest React API: React Hook

Testing out React (v16.8.0-alpha) Latest API

Screenshot 2019-01-12 at 1.02.27 AM.png

React Hooks

Take note that React Hooks are still in Alpha.

Sample code

React Hooks are available for functional component which are a "replacement" for react state in class component.

Using useState() you can create an array, where the first item in the array is the state, and the second item is a function to set the state.

Read more about React useState()

What makes hook really awesome is useEffect() function, because it replace 3 lifecycle hooks of react class component (componentDidMount, componentWillUnmount() & componentDidUpdate)

Read more about React useEffect()

Ultimately, with React Hooks, you are able to write even less codes and in a more functional approach.

Live version

Live version of the site is at https://superoo7.github.io/react-16.8.0-alpha/

The source code is on GitHub, which includes another few latest API (React.Suspense, Context API and Hooks)

Leave Testing latest React API: React Hook to:

Written by

Software Developer @ Coingecko

Read more #react posts


Best Posts From Johnson Lai

We have not curated any of superoo7's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.

More Posts From Johnson Lai