Gatsby build fail useContext - hello-world-starter #31976
-
DescriptionGatsby is failing to complete a successful build when I am using the react useContext hook. Not sure why this is happening Steps to reproduceDarkThemeContext.js
gatsby-browser.js
failed Building static HTML for pages - 1.173s - static-entry.js:263 Objects are not valid as a React child (found: object with keys {darkMode, setDarkMode}). If you meant to render a collection of children, use an array instead. Expected resultGatsby build should complete succesfully Actual resultGatsby build does not succesfully EnvironmentSystem: |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
https://github.com/avi312singh/FTYD-Fe/blob/main/gatsby-browser.js Here is the commit which seems to have broken gatsby build: avi312singh/FTYD-Fe@9206f48. (useContext was introduced) More build history on gatsby cloud (https://www.gatsbyjs.com/dashboard/5254933f-7a05-4838-825a-5f2b7dc19dd9/sites/33ff7dea-2af8-43f0-8155-23f89bf5f6f0/deploys) |
Beta Was this translation helpful? Give feedback.
-
This is an issue with your code as a minimal example shows that it works in Gatsby: https://codesandbox.io/s/usecontext-in-gatsby-2oylw Feel free to use that as a reference for your project. |
Beta Was this translation helpful? Give feedback.
-
Hi this was resolved by moving
|
Beta Was this translation helpful? Give feedback.
Hi this was resolved by moving
components
outside ofsrc/pages
Gatsby was trying to generate page for each component folder during build and it got DarkThemeContext (with no JSX being inside) and webpack failed to render any html at