React Hooks, officially released as part of React 16.8+. Hooks make it possible to take a React function component and add state to it or hook lifecycle methods.
// It takes a function useEffect(() => { // Called after every render, by default console.log('render!'); // If you want to implement componentWillUnmount, // return a function from useEffect return () => console.log('unmounting...') }) return "I'm a LifecycleDemo component" }
Consumer to grab the value from context // Notice this component didn't get any props return ( <NumberContext.Consumer> {value => <div>The number is {value}.</div>} </NumberContext.Consumer> ) }