Mutation Using Relay Medium

I am using Relay with React Native and have a problem logging in and logging out.

After logging in or logging out, Relay saves storage from the previous user. For this, I use Relay.Rendererand Relay.Environment. Like in, in each RendererI place a singleton object Environment.

The problem is that I previously did a mutation on an object Relay.Store, as in Relay.Store.commitUpdate(new CreateProfile(), callback).

Now it will not work. I think this is because Relay.Storeit knows nothing about the endpoints of the server. But Relay.Environmentdoes.

And now I'm using something like this this.props.relay.commitUpdate(new CreateProfile(), callback). It works very well when the parent component is wrapped like Relay.Container, so it has a relay object in the details.

But what should I do in components that are not Relay.Containersand do not have an object Relayin the details?

+4
source share
1 answer

Relay.Storeis a globally available instance of singleton Relay.Environmentand Relay.Store.commitUpdate()updates data in this global environment. But since you are using your own instance Relay.Environment, you need to use it to update it this.props.relay.commitUpdate(), as you noted. This updates the environment in which the container was processed.

, Relay.Container, . relay prop, :

<Child relay={this.props.relay} />

, Relay, Relay. , , :

onCreateProfile = () => {
  this.props.relay.commitUpdate(new CreateProfile());
};

render:

<Child onCreateProfile={this.onCreateProfile} />

, Relay.Container , Relay.Environment ( , , ).

+1

Source: https://habr.com/ru/post/1650184/


All Articles