Skip to content

Example for how to use React's Context API with Gatsby

License

Notifications You must be signed in to change notification settings

queen-raae/gatsby-context-api

 
 

Repository files navigation

gatsby-context-api

Example for how to use React's Context API with Gatsby

SSR Valhalla Setup

Use Apollo Studio to construct a query for use in getServerData

Apollo Studio

https://studio.apollographql.com/sandbox/explorer

Sandbox URL

https://valhallaexamples-prod.staging-valhalla-api.io/

Page

import React from 'react';
import { createClient } from '@urql/core';

const Page = ({ serverData }) => {
  console.log(serverData);
  return null;
};

export const getServerData = async () => {
  const client = createClient({
    url: 'https://valhallaexamples-prod.staging-valhalla-api.io/',
    requestPolicy: 'network-only'
  });

  const query = `
  {
    allContentfulAnimal(limit: 35)  {
      nodes {
        name
        animalType
        image {
          url
        }
      }
    }
  }
  `;

  const { data } = await client.query(query).toPromise();

  return {
    props: {
      data
    }
  };
};

export default Page;

About

Example for how to use React's Context API with Gatsby

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 94.7%
  • CSS 5.3%