-
Notifications
You must be signed in to change notification settings - Fork 255
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
fix(clerk-js): Replace generic ComponentContext with component-specific contexts #4486
Conversation
🦋 Changeset detectedLatest commit: fdcbbed The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@@ -74,6 +148,12 @@ export const useSignUpContext = (): SignUpContextType => { | |||
[], | |||
); | |||
|
|||
if (!context || context.componentName !== 'SignUp') { |
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.
For simplicity we retain the componentName check. In a future PR we can refactor this out since we always know that we're accessing a value from the expected Context.
const { componentName, ...ctx } = context; | ||
|
||
return { | ||
...ctx, | ||
componentName, | ||
}; |
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.
Looks like this could be simplified to just
const { componentName, ...ctx } = context; | |
return { | |
...ctx, | |
componentName, | |
}; | |
return context; |
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.
yeah this is left over from the previous implementation. When I refactor this to split these contexts into separate files and remove the componentName
check I'll clean this up as well!
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.
lgtm
Description
This PR replaces the generic
ComponentContext
provider with component-specific versions.The biggest benefit to this PR is reducing the amount of "magic" happening, and moving us towards a more typical approach to handling Context within React applications. Instead of a generic Context that can be one of 11 different types, we now have 11 separate Contexts. This adds a bit more safety in that there won't be an instance where the
SignIn
component tries to access the Context of another component (which we currently guard against via a runtime check ofcomponentName
). Ultimately it's a small change intended to simplify complexity and increase readability.Progress:
SignIn
SignUp
UserProfile
UserVerification
UserButton
OrganizationSwitcher
OrganizationList
OrganizationProfile
CreateOrganization
GoogleOneTap
Waitlist
Checklist
npm test
runs as expected.npm run build
runs as expected.Type of change