-
Notifications
You must be signed in to change notification settings - Fork 338
chore(ui-react-core): Migrate useInitMachine to ui-react-core #2754
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
Conversation
|
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.
Thanks for doing this and adding the unit tests. Left some feedback/questions
expect(initializeMachine).toHaveBeenCalledTimes(1); | ||
|
||
// change the input props of the hook to get the useEffect to run again | ||
data = { mutated: 'dataObject' }; |
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.
Prefer to avoid mutating test variables to achieve a desired behavior as it increases fragility and the behavior itself can be difficult for future maintainers to comprehend the context of.
As an alternative, the rerender
API probably provides handling it through the testing library, maybe try the docs
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.
Good call. I found a way to use the rerender
API to handle this
export default function useAuthenticatorInitMachine( | ||
data: AuthenticatorMachineOptions | ||
): void { | ||
const { route, initializeMachine } = useAuthenticator(({ route }) => [route]); |
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.
Not like a huge deal or anything but we could declare the selector param outside the scope of useAuthenticatorInitMachine
to give it a static reference between renders
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.
"React Hook useAuthenticator
cannot be called at the top level. React Hooks must be called in a React function component or a custom React Hook function."
...act-core/src/Authenticator/hooks/useAuthenticatorInitMachine/useAuthenticatorInitMachine.tsx
Outdated
Show resolved
Hide resolved
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 🚢
|
||
expect(initializeMachine).toHaveBeenCalledTimes(1); | ||
|
||
// change the input props of the hook to get the useEffect to run again | ||
data = { mutated: 'dataObject' }; | ||
rerender(); | ||
rerender({ data: modifiedData }); |
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.
🔥
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 of changes
Migrates
useInitMachine
hook to theui-react-core
package.useAuthenticatorInitMachine
Issue #, if available
Description of how you validated changes
Wrote unit tests, and tested for false positive.
Checklist
yarn test
passesBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.