React Hooks

React hooks allow us to use some React abilities outside of a React class component. Such as 'state' and 'setState'.

import React, { useState } from 'react';

export default MyComponent = () => {

  const [name, setName] = useState('Harry');

  const handleClick = () => {
    setName('Jacks');
  }

  return <div>
    <p>{name}</p>
    <button onClick={handleClick}>Set name as Jacks</button>;
  </div>
}


The important bit is this line:

const [name, setName] = useState('Harry');


The 'name' is the name of the state object. The 'setName' is the method we call to update the 'name'. The value we pass to the 'useState' method is the default state of 'name'.