Skip to content

Commit

Permalink
Add comment explaining why to avoid the 'useEffect()'.
Browse files Browse the repository at this point in the history
  • Loading branch information
elle-j committed Apr 5, 2024
1 parent f95ec3f commit 876281c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/realm-react/src/UserProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ export const UserProvider: React.FC<UserProviderProps> = ({ fallback: Fallback,
const [user, setUser] = useState<Realm.User | null>(() => app.currentUser);
const [, forceUpdate] = useReducer((x) => x + 1, 0);

// Support for a possible change in configuration
// Support for a possible change in configuration.
// Do the check here rather than in a `useEffect()` so as to not render stale state. This allows
// for the rerender to restart without also having to rerender the children using the stale state.
const currentUser = app.currentUser;
if (userWasUpdated(user, currentUser)) {
setUser(currentUser);
Expand Down

0 comments on commit 876281c

Please sign in to comment.