[GatsbyJS] This component must be used inside a <RecoilRoot> component error in build
See original GitHub issueI’m trying to use Recoil Js in a GatsbyJs application.
I configured <RecoilRoot>
in wrapRootElement
(also tried import { RecoilRoot } from 'recoil/dist/recoil.production'
as suggested in this issue) but I receive this error during gatsby build
script.
Am I missing something? How to use this lib in a GatsbyJs app?
Issue Analytics
- State:
- Created 3 years ago
- Comments:9
Top Results From Across the Web
ReactJS error is "This component must be used inside a ...
To use Recoil (A state management library for React) properly You have to add RecoilRoot wrap component(s). As we can read in documentation ......
Read more >This component must be used inside a <RecoilRoot ...
Hi, I followed the Quick start tutorial (https://docs.onflow.org/flow-js-sdk/flow-app-quickstart). I end up getting an error: This component ...
Read more >How to Use Recoil.js Library in Gatsby - Medium
RecoilRoot component is placed inside the wrapPageElement function, which is then exported from the gatsby-browser.js file. Gatsby · Gatsbyjs.
Read more >Part 2: Use and Style React Components - Gatsby
Import and use a pre-built component from another package. Create your own reusable “building block” component. Use component props to change the way...
Read more >How to Use Recoil.js Library in Gatsby - Morioh
To use Recoil library to persist state between components, RecoilRoot component needs to be placed at the top of the component tree.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just throwing this on here just in case anyone is stuck and they happen to have the same problem that I did.
❌Doesn’t work
✔ Works
Also, to reduce duplication, you can do this in
gatsby-browser.js
:@risakanagawa For sure, hope this helps.
First, know that the gatsby-browser file “…lets you…wrap your site in additional components…” - https://www.gatsbyjs.com/docs/browser-apis. You need to wrap your root element to allow passing the recoil state, for example:
Second, if you have the gatsby-ssr file then you pretty much need to do the same since “…There is an equivalent hook in Gatsby’s Browser API. It is recommended to use both APIs together.” - https://www.gatsbyjs.com/docs/ssr-apis/