In Next.js, props refer to the properties that are passed to a React component when it’s rendered. These properties hold data or functions that can be utilized within the component.
In the context of Next.js, when you define a page or a component and you want to pass data or functions to that component from its parent or from the Next.js infrastructure, you typically use props.
For example, in a Next.js page, you might have something like this:
javascriptCopy codeimport React from 'react';
const MyPage = (props) => {
// Accessing props passed to the page/component
const { title, content, onClickHandler } = props;
return (
<div>
<h1>{title}</h1>
<p>{content}</p>
<button onClick={onClickHandler}>Click Me</button>
</div>
);
};
export default MyPage;
In this scenario:
title,content, andonClickHandlerare all passed as props.- The
propsobject contains these values/functions, allowing you to access and use them within theMyPagecomponent.
These props can come from various sources such as parent components passing data, Next.js routing system, or other external sources when working with Next.js’s data fetching methods like getStaticProps or getServerSideProps.