Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

usestate in react js

import React, { useState } from "react";

const Counter = () => {
  // Here we use the useState -->
  const [count, setCount] = useState(0);

  // Here we make the function of the Count with setCount
  const onClick = () => {
    setCount(count + 1);
  };

  return (
    <div>
        <p>You Clicked {count} On The Button</p>
        <button onClick={onClick}>Click Me></button>
    </div>
  );
};

export default Counter;
Source by reactjs.org #
 
PREVIOUS NEXT
Tagged: #usestate #react #js
ADD COMMENT
Topic
Name
2+6 =