Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

React hook - useState function to use state without writing a class

0 votes
8 views
added Mar 12 in React by lcjr Second Warrant Officer (4,220 points)

Hooks is a new feature made available to React 16.8. They let us use state and other React features without writing a class.

import React, { useState } from 'react';

function Example() {
  // Declare a new state variable, which we'll call "count"
  const [count, setCount] = useState(0);

  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}>
        Click me
      </button>
    </div>
  );
}

 

Please log in or register to response this reference.

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...