showing results for - "counter with react hooks"
Sarah
13 Nov 2018
1import React, { useState } from 'react';
2
3function Example() {
4  // Declaración de una variable de estado que llamaremos "count"  const [count, setCount] = useState(0);
5  return (
6    <div>
7      <p>You clicked {count} times</p>
8      <button onClick={() => setCount(count + 1)}>
9        Click me
10      </button>
11    </div>
12  );
13}
Yannik
13 Jun 2019
1const { useState, useEffect, useRef } = React;
2
3function useInterval(callback, delay) {
4  const savedCallback = useRef();
5
6  // Remember the latest callback.
7  useEffect(() => {
8    savedCallback.current = callback;
9  }, [callback]);
10
11  // Set up the interval.
12  useEffect(() => {
13    let id = setInterval(() => {
14      savedCallback.current();
15    }, delay);
16    return () => clearInterval(id);
17  }, [delay]);
18}
19
20function App() {
21  const [counter, setCounter] = useState(0);
22
23  useInterval(() => {
24    setCounter(counter + 1);
25  }, 1000);
26
27  return <h1>{counter}</h1>;
28};
29
30ReactDOM.render(
31  <App />,
32  document.getElementById('root')
33);
queries leading to this page
react hooks countercounter with only function in hooksreact hooks on click execute a functionreact hooks counter examplereact ks counter hooksuse state counter reactcounter program using usestate in react js examplereact hooks set countercounter code with usestate reactcounter react hookreact counter app with hooksadd counter react hookssetstate hook counterusestate use with exporeact counter usestatecounter with hooks react nativereact counter without hookssimple countter using react hooksreact counter examplereact hooks counter example with useeffect hookcounter example usestate 5chookcounter function in react hooksusestate counter reacthow to increase counter hooks reactrender counter react hookhook counter reacthow to create a counter app in react hookscounter hooksincrease counter react hookscounter with hookscounter program using react hooksreact use state counteautomated counter with react hooksuse state hook countercounter hooks in reactcounter app in react without hooksreact counter component state hookusestate hook countersimple counter with hooksusestate increment decrementreact usestate counterreact counter hookshooks automatic counter reactcounter in react hookscounter button click react hooksusestate with counter jssimple counter react hooksreact hooks counter npmhooks counter examplereact hooks counter function increasing by one react counter with hooksusestate react hooksreact hook counterclick counter using react functional componentcounter with react hookscounter app react hookscounter using hooksusestate react countercreate counter with react hooksreact hooks counter 5ccounter button react hooksreact hook counter appreact hooks countusestate example countercounter using hooks reactreact view counter hookscreating a counter with a react hookbuilding a counter in react hookscounter in react usestatecounter react hooksusestate increment by 1 and decrement react componentcounter using react hookscounter app using hooksa counter react hookscount with react hookscounter in react using hookshow to make simple counter in react hookhow counter example in react hookscounter hook reactreact usestate counter examplehow to create a counter with usestatehooks react countersimple counter in react react hookscounter with react hooks