Skip to content
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 usePartFields hook #7868

Merged
merged 1 commit into from
Aug 14, 2024

Conversation

SchrodingersGat
Copy link
Member

No description provided.

@SchrodingersGat SchrodingersGat added bug Identifies a bug which needs to be addressed user interface User interface Platform UI Related to the React based User Interface labels Aug 14, 2024
@SchrodingersGat SchrodingersGat added this to the 0.17.0 milestone Aug 14, 2024
Copy link

netlify bot commented Aug 14, 2024

Deploy Preview for inventree-web-pui-preview ready!

Name Link
🔨 Latest commit 027c6ae
🔍 Latest deploy log https://app.netlify.com/sites/inventree-web-pui-preview/deploys/66bbfb0a74206000089b5b06
😎 Deploy Preview https://deploy-preview-7868--inventree-web-pui-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 100 (no change from production)
Accessibility: 86 (no change from production)
Best Practices: 92 (no change from production)
SEO: 70 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@SchrodingersGat SchrodingersGat merged commit 2244f5f into inventree:master Aug 14, 2024
25 checks passed
@SchrodingersGat SchrodingersGat deleted the part-fields-fix branch August 14, 2024 00:49
@@ -13,6 +13,8 @@ export function usePartFields({
}: {
create?: boolean;
}): ApiFormFieldSet {
const settings = useGlobalSettingsState.getState();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure, that this works?

What was your initial issue, that you tried to solve with this? That the useMemo was not retriggered when the global state updated?

Isn't the Zustand syntax something like this in a reactive way then:

Suggested change
const settings = useGlobalSettingsState.getState();
const settings = useGlobalSettingsState();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initial issue was that the call to settings was buried inside the lower useMemo call which was only updated when create changed. So, AFAIK, settings value was never being re-evaluated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it should be reevaluated, on the initial render of the component and if create would have changed.

Using .getState is used to get the state outside of the component. E.g. in a hook. Ref: https://github.com/pmndrs/zustand?tab=readme-ov-file#readingwriting-state-and-reacting-to-changes-outside-of-components

If you want to subscribe to the state and bind it to a react state, just call the store, the store is a hook. But I'm not sure if this whole change is really necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Identifies a bug which needs to be addressed Platform UI Related to the React based User Interface user interface User interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants