Thiago Viana Enge
Thiago Viana Enge

Reputation: 21

Pass data from page to another

I recently started working with next.js, although I already have some experience with react, I have the following folder structure:

/segments 
  -index.js
  -[slug].js

Scenario: On page [url] / segments I get the list of segments by making a call to my api, which returns an array with all the information for each segment -> I display the list of segments for the user -> User chooses the segment and navigates to [url] / segments / slug. At this point I would like that on this page [slug] .js to receive the segment that the user chose (since everything I need is already in the object) without the need for another call to the api. I know I can use context for this, but I was wondering if next.js can solve this problem without having to use the global scope. Just passing a fetched data on one page to another. Thanks All

Upvotes: 2

Views: 11212

Answers (1)

Hooman
Hooman

Reputation: 1925

You must take advantage of custom _app.js to share data among your application.

I have answered in detail to the same question which you can check it out in the following link:

Next.js: Reduce data fetching and share data between pages

Upvotes: 1

Related Questions