Aller au contenu principal

<RecoilRelayEnvironmentProvider>

The <RecoilRelayEnvironment> component enables you to use a Relay Environment with Recoil GraphQL selectors or atom effects in its child components. The <RelayEnvironmentProvider> component enables you to use a Relay Environment with Relay hooks in its child components. <RecoilRelayEnvironmentProvider> is simply a convenience component which combines these two.


Props​

  • environment - The Relay Environment object to register.
  • environmentKey - The EnvironmentKey object to associate this environment with.

Example​

const myEnvironmentKey = new EnvironmentKey('My Environment');

function MyApp() {
return (
<RecoilRoot>
<RecoilRelayEnvironmentProvider
environment={myEnvironemnt}
environmentKey={myEnvironmentKey}>
{/** My App **/}
</RecoilRelayEnvironmentProvider>
</RecoilRoot>
)
}
const myQuery = graphQLSelector({
key: 'MyQuery',
environment: myEnvironmentKey,
query: graphql`...`,
variables: {},
});

function MyComponent() {
const results = useRecoilValue(myQuery);
}