Skip to main content
Version: v12.0.0

useRelayEnvironment

useRelayEnvironment#

Hook used to access a Relay environment that was set by a RelayEnvironmentProvider:

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;

Is this page useful?