Reading Class 22 - martinbalke-401-adavanced-js/seattle-javascript-401n14 GitHub Wiki

Hooks Api

React Hooks API is a tool that allows you to grant a functional component state. Using the setState() function you are able to set a getter and a setter for a state variable while inside of a functional component. This is useful for a lot of reasons. One is that you don't need to worry about contextual this when defining functions, this allows for more easily understandable code and less headaches. Another advantage is that you simply have to write less code in order to achieve the same result.

class Thing extends React.Component { constructor(props){ super(props) this.state = {thing: 1} } }

versus

function thing(props){ const [thing, setThing] = useState(1); }