Created
May 17, 2021 15:10
-
-
Save PaulieScanlon/0fae5556f77c3f5bcb7b12942326c02b to your computer and use it in GitHub Desktop.
Contentful Render - Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
const ContentfulRender = ({ children }) => { | |
return <>{process.env.GATSBY_CONTENTFUL_KEY ? <>{children}</> : null}</>; | |
}; | |
export default ContentfulRender; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
This was what i was thinking but i think the problems might come if
<SomeContentfulComponent />
has a GraphQL query inside of it that relies on Contentful data. Reason being is that if you're using a Gatsby plugin to source the data from Contentful then the API key needs to be there or you'll get an error when Gatsby buildsThe other option i was thinking about would be to create multiple Contentful spaces which have their own keys. Folks who shouldn't see certain content would get a key to a dummy or blank workspace. This way the site sill works as expected it just returns no data. You might need to add a few
data ? <div /> : null
in places where the UI is expecting an array and it might be null when the blank key is used.