Skip to content

Instantly share code, notes, and snippets.

@giautm
Created May 9, 2020 05:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giautm/c45c8cfd375dd59993142094dc2de4ad to your computer and use it in GitHub Desktop.
Save giautm/c45c8cfd375dd59993142094dc2de4ad to your computer and use it in GitHub Desktop.
import * as React from "react";
const faunadb = require("faunadb");
const q = faunadb.query;
export const FaunaContext = React.createContext();
export const FaunaProvider = ({ children, faunaSecret }) => {
const fauna = React.useMemo(() => {
if (!faunaSecret) {
throw new Error(`No faunaSecret found, skipping client creation`);
}
const client = new faunadb.Client({
secret: faunaSecret
});
return { client, q };
}, [faunaSecret]);
return (
<FaunaContext.Provider value={fauna}>{children}</FaunaContext.Provider>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment