Skip to content

Instantly share code, notes, and snippets.

@okmttdhr
Created March 13, 2020 07:23
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 okmttdhr/02c2b259a890f18f05c1f2a6c9ff59cf to your computer and use it in GitHub Desktop.
Save okmttdhr/02c2b259a890f18f05c1f2a6c9ff59cf to your computer and use it in GitHub Desktop.
gRPC request client as React.Context
import React from "react";
import { MessengerClient } from "./messenger/MessengerServiceClientPb";
interface GRPCClientContextValue {
messengerClient?: MessengerClient;
}
const defaultContextValue = {
messengerClient: new MessengerClient(`http://localhost:8080`)
};
export const GRPCClientContext = React.createContext(
{} as GRPCClientContextValue
);
export const GRPCProvider: React.FC<{}> = ({ children }) => {
return (
<GRPCClientContext.Provider value={defaultContextValue}>
{children}
</GRPCClientContext.Provider>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment