Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react using button props child

function Button(props){


  return (
  <button onClick={props.onClickFunction}>
     +1
      </button>);
}
function Display(props){
  return(
  <div>{props.message}</div>);
}
function App(){
    const [counter, setCounter] = useState(0);
   const handleClick = () => setCounter(counter+1);
  return (
      <>
      <Button onClickFunction= {handleClick}/>
      <Display message={counter}/>
      </> );
}
ReactDOM.render(
<App />,
  document.getElementById('mountNode')

  );
Source by jscomplete.com #
 
PREVIOUS NEXT
Tagged: #react #button #props #child
ADD COMMENT
Topic
Name
9+5 =