Successfully added
Snipps
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:
Leave a Comment
All fields are required. Your email address will not be published.
Comments(2)
Plexhalaubs
6/5/2023 7:44:07 PMZapforelaubs
6/5/2023 9:35:13 PM