showing results for - "react hooks demo"
Ousmane
18 Sep 2018
1// Same basic function as in reactjs site, with a bit of improvement
2
3import React, { useState, useEffect } from 'react';
4
5export default function Homepage() {
6  // Declare a new state variable, which we'll call "count"
7    const [count, setCount] = useState(0);
8
9    useEffect(() => {
10        document.title = `You clicked ${count} times`;  
11    })
12
13  return (
14    <div>
15      <h2>You clicked {count} times!</h2>
16
17      <button onClick={() => setCount(count > 0 ? count - 1 : count)}> Decrement </button>
18      <button onClick={() => setCount(count + 1)}> Increment </button>
19    </div>
20  );
21}