跳至主要内容
版本:v18.0.0

useRelayEnvironment

useRelayEnvironment

用于访问由 RelayEnvironmentProvider 设置的 Relay 环境的钩子。

const React = require('React');

const {useRelayEnvironment} = require('react-relay');

function MyComponent() {
const environment = useRelayEnvironment();

const handler = useCallback(() => {
// For example, can be used to pass the environment to functions
// that require a Relay environment.
commitMutation(environment, ...);
}, [environment])

return (...);
}

module.exports = MyComponent;