Successfully added
React
by Patrik
Pass a Parameter to an onClick Event Handler
Another common use case for event handlers is passing a parameter to a function in React so it can be used later. For example:
import React from "react";
const App = () => {
const sayHello = (name) => {alert(`Hello, ${name}!`);
};
return (
<button onClick={() => {sayHello("John");}}>Say Hello</button>
);
};
export default App;
Referenced in:
Comments(2)
Zapforelaubs
6/5/2023 9:35:13 PMPlexhalaubs
6/5/2023 7:44:07 PM