Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

react onclick function

// Wrong way: This alert fires when the component renders, not when clicked!
<button onClick={alert('You clicked me!')}>

// Correct way:                
<button onClick={() => alert('You clicked me!')}>
Source by beta.reactjs.org #
 
PREVIOUS NEXT
Tagged: #react #onclick #function
ADD COMMENT
Topic
Name
5+8 =