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;
此页面是否有用?