I am currently using Next.js and it's completely new to me. I am trying to get the search functionality to work but I am unable to get it.
Basically, I am trying to search data using a textbox in a different component and display the data in a different component.
I have searched for several solutions in stack overflow but couldn't find any related solution. I believe that the problem is I am not able to pass the data from one component to another.
This is a snippet from my app.js
function sample({ Component, pageProps }) {
.
.
.
const [searchState, setSearch] = useState("")
.
.
.
return{
<div className='search'>
<input type='text' className='searchtext' placeholder='search...' onChange=
{(event) => {setSearch(event.target.value)} } />
</div>
.
.
.
<div className="sub-navs">
<Link
href="/"
render={props => { <Home {...props} searchData = {searchState} /> }}
>
<a className="nav-btn">
Home
</a>
</Link>
</div>
}
This is a snippet from my index.js
export default function Home(searchData) {
.
.
.
console.log(searchData)
Outputs
In the first code snippet, I am able to get the search text (string) but in the second it's showing an empty object.