Next.js Discord

Discord Forum

Pass data from layout to children

Answered
maslomeister posted this in #help-forum
Open in Discord
Is it possible to do some fetch in layout and then pass that data to children?

example usage

/verify

has a general layout and verifies the code from searchParams

/verify/page1,/verify/page2,/verify/page3 are unique, but the code verification is the same, can i somehow verify the code using fetch request in the layout of /verify and pass response down to any children component?
Answered by B33fb0n3
you shouldn't fetch in layout. Technically you can, but you shouldn't. You should create a verify page and maybe make it dynamics (I don't know what page1, page2 and so on is) and get the verify key. Fetch the data inside your page.js and pass it to the components via the props @maslomeister
View full answer

2 Replies

you shouldn't fetch in layout. Technically you can, but you shouldn't. You should create a verify page and maybe make it dynamics (I don't know what page1, page2 and so on is) and get the verify key. Fetch the data inside your page.js and pass it to the components via the props @maslomeister
Answer
Oh, forgot about dynamic pages, that should work, thanks!