Created
March 13, 2020 07:23
-
-
Save okmttdhr/02c2b259a890f18f05c1f2a6c9ff59cf to your computer and use it in GitHub Desktop.
gRPC request client as React.Context
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"; | |
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