Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support environment contentful parameter #4

Merged
merged 6 commits into from
Jan 23, 2020

Conversation

krambuhl
Copy link
Contributor

@krambuhl krambuhl commented Oct 17, 2019

Adds support for the environment contentful client parameter.

Thanks for your effort on this package, it's making our next.js project much more straightforward. We appreciate your timeliness, since this update is to better support a client project. Let me know if I can do anything to make your life a little easier.

@ryanhefner ryanhefner added this to To Do in Open Sourcery 🔮 Nov 26, 2019
@waelhasan
Copy link

Hi @ryanhefner
Thanks for the great work you are doing here, we use your package and it makes our life easier :)
But we face the same issue as @krambuhl, and it would be great if this pull request is merged, so that we can have this feature in our code

@diegopamio
Copy link

+1, this is very much needed for my project too.

@ryanhefner ryanhefner merged commit 4ef8e1b into ryanhefner:master Jan 23, 2020
Open Sourcery 🔮 automation moved this from To Do to Done Jan 23, 2020
@ryanhefner
Copy link
Owner

Thank @krambuhl! Sorry this took so long to get in. I hope this helps with your projects, @waelhasan and @diegopamio!

Please let me know if you run into any other issues with this package, or react-contentful, and I will try to be more prompt in addressing any issues you run into.

@diegopamio
Copy link

Thank you!

@diegopamio
Copy link

I'm having the issue you mentioned about contentful complaining with No contentful context passed to <Query />

@ryanhefner
Copy link
Owner

Hey @diegopamio, are you using withContentful in your _app.xfile? That error would be due to a Query existing outside the ContentfulProvider.

@diegopamio
Copy link

Yes, I'm using withContentful in the _app.js file, like this:

const MyApp = ({Component, pageProps, disableShutdown}) => {
  useEffect(() => {
    const jssStyles = document.querySelector('#jss-server-side');
    if (jssStyles) {
      jssStyles.parentElement.removeChild(jssStyles);
    }
  }, []);

  const {data, error, fetched, loading} = useContentful({
    contentType: 'Page',
    query: {
      contentType: 'recurrentInteraction',
      id: '2qAa1JM13xNcOVOy5X0rAT',
    }
  });
  return <>
    <ThemeProvider theme={theme}>
      <FullStory org={ORG_ID}/>
      <CssBaseline/>
      {
        (!data) && (
          <div>
            <div>Error retrieving contentful data</div>
            <div>
              error:
              {error || 'null'}
            </div>
          </div>
        ) ||
        (data) || (
          <>
            <Head>
              <title>{data.fields.siteTitle || 'Global IT Burnout Index'}</title>
              <meta name="description" content={data.fields.siteDescription || 'Global IT Burnout Index'}/>
              <meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width"/>
            </Head>
            <Component {...pageProps} contentfulData={data} disableShutdown={disableShutdown}/>
          </>)
      };
      )}
    </ThemeProvider>
  </>;

};

const witGAApp = withGA('UA-156049947-1', Router)(MyApp);

export default withContentful({
  accessToken, host, space, environment,
})(witGAApp);

Is that an invalid combination? How could I achieve having the top query otherwise? Thanks!

@ryanhefner
Copy link
Owner

ryanhefner commented Mar 2, 2020

Ah, interesting, yeah that won't work since right now only the returned tree is being wrapped in the ContentfulProvider, so there is no context available for useContentful in MyApp.

I suppose you could take all the data dependent stuff and move it into its own component, and pass the relevant _app props into it, kind of like a Layout component or something. Let me know if that works/makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants