-
Notifications
You must be signed in to change notification settings - Fork 50
Replace useState calls with discriminated union #352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Replace useState calls with discriminated union #352
Conversation
| } finally { | ||
| setLoading(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this action call fails above then without this finally the loading state stays loading forever. We probably need to keep this in some form to reset the loading state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed.
src/components/authkit-provider.tsx
Outdated
| const [featureFlags, setFeatureFlags] = useState<string[] | undefined>(initialAuth?.featureFlags); | ||
| const [impersonator, setImpersonator] = useState<Impersonator | undefined>(initialAuth?.impersonator); | ||
| const [loading, setLoading] = useState(!initialAuth); | ||
| const [authState, setAuthState] = useState<AuthState>(() => createAuthState(initialAuth)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this should be a useReducer call instead? That way the auth state and loading boolean can be updated independently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. I have replaced useState with useReducer.
|
@nicknisi I have updated the PR with the |
This PR replaces 10 separate
useStatecalls insideauthkit-provider.tsxwith a single discriminated union:This brings two benefits to the codebase:
Note: There are no changes to the public API. All existing tests pass.