Skip to main content
Version: v14.0.0


Relay Environment Provider

In order to render Relay components, you need to render a RelayEnvironmentProvider component at the root of the app:

// App root

const {RelayEnvironmentProvider} = require('react-relay');
const Environment = require('MyEnvironment');

function Root() {
return (
<RelayEnvironmentProvider environment={Environment}>
{/*... */}
  • The RelayEnvironmentProvider takes an environment, which it will make available to all descendant Relay components, and which is necessary for Relay to function.

Accessing the Relay Environment

If you want to access the current Relay Environment within a descendant of a RelayEnvironmentProvider component, you can use the useRelayEnvironment Hook:

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

function UserComponent(props: Props) {
const environment = useRelayEnvironment();

return (...);

Is this page useful?

Help us make the site even better by answering a few quick questions.