how to pass event with a parameter in a function react code example
Example 1: how to pass a value to a react funtion without immediately firing it
<button onClick={(e) => {
this.clickMe(e, someParameter)
}}>Click Me!</button>
Example 2: passing argument to function handler functional compoent javascript react
function MyComponent(props) {
function handleChange(event, data){
console.log(event.target.value);
console.log(data)
}
return <button onClick={(event) => handleChange(event, 'Some Custom Value')} value='Foo'>Click</button>
}
Example 3: react pass parameter to component
import React, { Component } from 'react'; class App extends Component { render() { return ( <div> <Greeting /> </div> ); }} class Greeting extends Component { render() { const greeting = 'Welcome to React'; return <h1>{greeting}</h1>; }} export default App;