Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react increment multipying button click

function Button(props){


  return (
  <button onClick={props.onClickFunction}>
     *{props.increment}
      </button>);
}
function Display(props){
  return(
  <div>{props.message}</div>);
}
function App(){
    const [counter, setCounter] = useState(0);
   const handleClick1 = () => setCounter(counter+1);
     const handleClick2 = () => setCounter(counter*5);
     const handleClick3 = () => setCounter(counter*10);
     const handleClick4 = () => setCounter(counter*100);
  return (
      <>
      <Button onClickFunction= {handleClick1} increment={1}/>
       <Button onClickFunction= {handleClick2} increment={5}/>
       <Button onClickFunction= {handleClick3} increment={10}/>
       <Button onClickFunction= {handleClick4} increment={100}/>
      <Display message={counter}/>
      </> );
}
ReactDOM.render(
<App />,
  document.getElementById('mountNode')

  );
Source by jscomplete.com #
 
PREVIOUS NEXT
Tagged: #react #increment #multipying #button #click
ADD COMMENT
Topic
Name
6+7 =