What is the best way to manage relay environment at logging out.
- Dominant language
- Rust
- Stars
- 19k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
Hi all.
I'm in making [relay-boilerplate](https://github.com/dooboolab/expo-relay-boilerplate) now.
It uses relay-hooks, `RelayEnvironmentProvider` in order to set a relay environment.
Previously, I faced [the problem resetting relay environment instance on authentication flow](https://github.com/facebook/relay/issues/3101) but I found the way is managed by the global state on the provider.
Here's my code.
- [src/relay/index.ts](https://github.com/dooboolab/expo-relay-boilerplate/blob/40d293fc42ff6be604c614349726ca0fb3613482/src/relay/index.ts#L18)
- [src/providers/AuthProvider.tsx](https://github.com/dooboolab/expo-relay-boilerplate/blob/40d293fc42ff6be604c614349726ca0fb3613482/src/providers/AuthProvider.tsx#L28)
- [reset relay](https://github.com/dooboolab/expo-relay-boilerplate/blob/40d293fc42ff6be604c614349726ca0fb3613482/src/providers/AuthProvider.tsx#L57)
```typescript
// App.tsx
function RelayEnvironmentWrapper({ children }): ReactElement {
// relay is managed by AuthContext
const {
state: { relay },
} = useAuthContext();
return (
}>
}>{children}
);
}
function ProviderWrapper(): ReactElement {
...
return (
// RelayEnvironmentWrapper wrapped App component
);
}
export default ProviderWrapper;
```
```typescript
// HeaderRightWidget.tsx
const HeaderRightWidget: FC = () => {
const {
state: { user },
resetUser,
} = useAuthContext();
const handleSignOut = (): void => {
// It'll be logout when executed resetUser of AuthContext.
resetUser();
};
return (
{user?.name || 'no-name'}
);
};
```
I wanna find the best way for managing relay environment when users logging out/on and share it with your opinion.
If you can share a good way, please leave me a comment.
Thanks for reading.
Contributor guide
Assessment
This issue has not been assessed yet.