Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

counter with react hooks

import React, { useState } from 'react';

function Example() {
  // Declaración de una variable de estado que llamaremos "count"  const [count, setCount] = useState(0);
  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}>
        Click me
      </button>
    </div>
  );
}
Comment

automated counter with react hooks

const { useState, useEffect, useRef } = React;

function useInterval(callback, delay) {
  const savedCallback = useRef();

  // Remember the latest callback.
  useEffect(() => {
    savedCallback.current = callback;
  }, [callback]);

  // Set up the interval.
  useEffect(() => {
    let id = setInterval(() => {
      savedCallback.current();
    }, delay);
    return () => clearInterval(id);
  }, [delay]);
}

function App() {
  const [counter, setCounter] = useState(0);

  useInterval(() => {
    setCounter(counter + 1);
  }, 1000);

  return <h1>{counter}</h1>;
};

ReactDOM.render(
  <App />,
  document.getElementById('root')
);
Comment

simple counter with react hook

import { useState } from "react";

function App() {
  return (
    <div className="App">
      <Counter></Counter>
    </div>
  );
}

function Counter() {
  const [count, setCount] = useState(0);
  const increaseCount = () => setCount(count + 1);
  const decreaseCount = () => setCount(count - 1);
  return (
    <div>
      <h1>Count: {count}</h1>
      <button onClick={increaseCount}>Increase</button>
      <button onClick={decreaseCount}>Decrease</button>
    </div>
  );
}

export default App;

Comment

PREVIOUS NEXT
Code Example
Javascript :: jQuery - Set 
Javascript :: JavaScript / jQuery DOM Selectors 
Javascript :: datatable all items in one line 
Javascript :: hide loader if datatable data loaded jquery 
Javascript :: convert to slug javascript 
Javascript :: single page application example javascript 
Javascript :: fingerprint 
Javascript :: symbol in keyword for arrow below 
Javascript :: window alert javascript css 
Javascript :: gatsby js quick start 
Javascript :: phaser place on rectangle 
Javascript :: phaser create animation from canvas texture 
Javascript :: phaser animation show on start 
Javascript :: como usar variables en selector jquery 
Javascript :: axios imgbb 
Javascript :: get random hsl color js 
Javascript :: getauth firebase admin node.js 
Javascript :: vue mount modal to body 
Javascript :: js floor a number 
Javascript :: TypeError: expressValidator is not a function 
Javascript :: schema 
Javascript :: javascript this = that 
Javascript :: javascript no decimal places 
Javascript :: process node.js example 
Javascript :: mongoose getters 
Javascript :: react-native spinner 
Javascript :: java script removing first three indexes 
Javascript :: spread operator react array 
Javascript :: javascript fadeout without jquery 
Javascript :: update text react native 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =