BlogPostBox.tsx.ts
I’m hoping someone can help me understand an issue I’m having with dynamic pages. I’m fairly sure I have it set up correctly, however when I render the page using NextJS, the parameter is undefined inside the data component.
uid
as passed to useFetchBlogPost
is undefined
I can’t share it all, but basically I’m calling this:
PLASMIC.fetchComponentData(`/blog/post/example-slug`)
This generates the correct meta object
And I’ve made sure that the dynamic value is hooked up to $ctx.params.slug
in the Plasmic editor
This is the blog post component
Untitled.ts
The root provider is inside _app
as there are some shared components on every page
How does PlasmicComponent
actually get the page parameters?
I’m super lost, I tried a few different things.
tiago
March 2, 2023, 3:51pm
8
Hi @better_mockingbird ! Your page params are in pageMeta.params
. The way to pass them so $ctx.params.slug
works is to use <PlasmicRootProvider pageParams={pageMeta.params} />
. See this example: https://docs.plasmic.app/learn/nextjs-quickstart/#auto-load-all-plasmic-pages
tiago
March 2, 2023, 3:54pm
9
If for some reason you can’t use PlasmicRootProvider when you have the pageMeta (I’m not sure what’s your setup), you can use PageParamsProvider (from @plasmicapp /host) instead, like:
<PageParamsProvider params={pageMeta.params}>
<PlasmicComponent component={pageMeta.displayName} />
</PageParamsProvider>
I’m pretty sure I tried that, but will try again with your specific example
Ok so looking at the react tree, there are two PageParamsProvider’s
This one has undefined params
This one is rendered inside the BlogPost component
If I remove the explicit PageParamsProvider, all the tree is left with is the first example, which is undefined
What I don’t understand is why uid
isn’t populated with the value when it is set up to do that in the editor?