-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
This seems similar to: #27
The docs for the React SDK recommend setting the default user using client.setDefaultUser: https://configcat.com/docs/sdk-reference/react/#default-user
const currentUser = { identifier: 'john@example.com' };
export const SetConfigCatUserComponent = () => {
const client = useConfigCatClient();
const [user] = useState(currentUser);
useEffect(() => {
client.setDefaultUser(user);
}, [client, user]);
return null;
};However, it appears that when client.setDefaultUser is called, this doesn't automatically trigger useFeatureFlag() calls throughout a React app to start recalculating their values (in case they might be different based on the new user).
To reproduce
- Have
useFeatureFlag()calls in your app that will return true if your user is X, false if not - Have the default user be
undefined - Asynchronously set the default user to be user X using
client.setDefaultUser - Observe that the
useFeatureFlag()calls don't start returning true simply as a result of callingclient.setDefaultUser
Expected behavior
client.setDefaultUser(), or another SDK-provided function, would integrate with React state and immediately cause useFeatureFlag() calls throughout the app to start returning proper values for the new user.
SDK version
- configcat-react: 5.0.3
- @configcat/sdk: 1.0.2
SDK configuration
import { ConfigCatProvider, useConfigCatClient } from "configcat-react";
/** Keeps the ConfigCat client's default user in sync with session */
const ConfigCatUserSync = () => {
const client = useConfigCatClient();
const { session } = useSessionContext();
useEffect(() => {
if (session) {
client.setDefaultUser({
identifier: String(session.idPayor),
email: session.email ?? undefined,
custom: { account: String(session.idAccount) }
});
} else {
client.setDefaultUser({ identifier: `anonymous` });
}
}, [client, session]);
return null;
};
const Navigation = () => (
<SessionProvider>
<ConfigCatProvider sdkKey={window.settings.CONFIGCAT_SDK_KEY}>
<ConfigCatUserSync />
<Router>
<App />
</Router>
</ConfigCatProvider>
</SessionProvider>
);Logs
N/A
Language/Framework version
React
Platform
macOS 15, Chrome 145
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working