-
Notifications
You must be signed in to change notification settings - Fork 242
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) O3-4274: Use useRef instead of useState for useVisitFormCallbacks #2157
base: main
Are you sure you want to change the base?
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 this change, @Bharath-K-Shetty . Please clean up your code before submitting it. Remove the extra whitespace and strange comments.
packages/esm-patient-chart-app/src/visit/visit-form/visit-form.component.tsx
Show resolved
Hide resolved
packages/esm-patient-chart-app/src/visit/visit-form/visit-form.component.tsx
Outdated
Show resolved
Hide resolved
packages/esm-patient-chart-app/src/visit/visit-form/visit-form.component.tsx
Outdated
Show resolved
Hide resolved
packages/esm-patient-chart-app/src/visit/visit-form/visit-form.component.tsx
Show resolved
Hide resolved
patientUuid={patientUuid} | ||
visitFormOpenedFrom={openedFrom} | ||
setVisitFormCallbacks={setVisitFormCallbacks} | ||
|
||
visitFormCallbacksRef={visitFormCallbacksRef} // Pass the ref instead |
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.
Don't include comments that won't make sense to someone reading this code later. The whole point of comments is to make code less confusing.
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.
Sorry for that.I will remove the unnecessary comments and whitespaces.Thankyou for the feedback..!
Please add a video demonstrating that everything still behaves as expected. |
….component.tsx Co-authored-by: Brandon Istenes <[email protected]>
….component.tsx Co-authored-by: Brandon Istenes <[email protected]>
783de5b
to
7945ebd
Compare
Hey @brandones,I’ve made the changes as requested and updated the PR. Let me know if any further changes are needed. Thank you |
Requirements
Summary
This PR refactors the useVisitFormCallbacks hook by replacing the usage of useState with useRef. The primary goal of this change is to improve performance by avoiding unnecessary re-renders triggered by state updates. useRef is used to persist values across renders without causing re-renders, which is particularly beneficial in the case of form callbacks where state persistence is needed but without affecting component lifecycle.
This change ensures that the form callbacks are maintained correctly across renders, while reducing the overhead associated with state management in React.
Jira Issue: O3-4274
Screenshots
O3-4274.mp4
Related Issue
https://openmrs.atlassian.net/browse/O3-4274
Other