It's mentioned here that it is not recommended to pass down large amounts of data via the page context when creating pages with createPage. If this is not recommended for performance reasons - _what is_ the recommended method to dynamically create pages that do require large amounts of data?
For context, what we're doing now is running a query for all page data in the onCreatePage hook, getting the results, looping through and calling createPage for each page and passing the page data via the context - and we're doing this for about a hundred pages and growing. Each page contains roughly 5-10 kB of data in a .yml file.
Each page contains roughly 5-10 kB of data in a .yml file.
I don't think that would be considered overly large, so it's not of too much concern
what is the recommended method to dynamically create pages that do require large amounts of data
Pass something unique to the page (like an ID or a slug) and use page queries and static queries in the components to pull the data back in for consumption. It helps keep data clean as it's obvious what components need and you only source exactly that data. By passing through a pageContext, it's just one huge object from Gatsby's perspective.
Thank you for opening this!
As our tutorial explains you should pass a unique identifier via context and use that as a variable in your template query: https://www.gatsbyjs.org/tutorial/part-seven/
We're marking this issue as answered and closing it for now but please feel free to comment here if you would like to continue this discussion. We also recommend heading over to our communities if you have questions that are not bug reports or feature requests. We hope we managed to help and thank you for using Gatsby!
Most helpful comment
I don't think that would be considered overly large, so it's not of too much concern
Pass something unique to the page (like an ID or a slug) and use page queries and static queries in the components to pull the data back in for consumption. It helps keep data clean as it's obvious what components need and you only source exactly that data. By passing through a pageContext, it's just one huge object from Gatsby's perspective.