0 day streak
javascript / beginner
Snippet

Arrow Functions in Next.js Components

Arrow functions provide a shorter syntax for writing functions. They are commonly used in React components and event handlers within Next.js applications.

snippet.js
javascript
1
2
3
4
const MyButton = ({ label }) => {
const handleClick = () => console.log('Clicked!');
return <button onClick={handleClick}>{label}</button>;
};
nextjs
Breakdown
1
const handleClick = () => ...
Defines a concise function using the arrow (=>) syntax.
2
onClick={handleClick}
Passes the function as a reference to the click event.