<RecoilRelayEnvironmentProvider>
The <RecoilRelayEnvironment>
组件允许您在子组件中使用 Relay 环境与 Recoil GraphQL 选择器 或 原子效果。The <RelayEnvironmentProvider>
组件允许您在子组件中使用 Relay 环境与 Relay hooks。<RecoilRelayEnvironmentProvider>
只是一个方便的组件,它将这两个组件结合在一起。
属性
environment
- 要注册的 Relay 环境对象。environmentKey
- 要将此环境关联到的EnvironmentKey
对象。
示例
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);
}