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) O3-4274: Use useRef instead of useState for useVisitFormCallbacks #2157

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Bharath-K-Shetty
Copy link

@Bharath-K-Shetty Bharath-K-Shetty commented Dec 14, 2024

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. If there is a ticket, make sure your PR title includes a conventional commit label. See existing PR titles for inspiration.
  • My work conforms to the OpenMRS 3.0 Styleguide and design documentation.
  • My work includes tests or is validated by existing tests.

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

@brandones brandones changed the title (Refactor) O3-4274: Use useRef instead of useState for useVisitFormCallbacks (fix) O3-4274: Use useRef instead of useState for useVisitFormCallbacks Dec 15, 2024
Copy link
Contributor

@brandones brandones left a 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.

patientUuid={patientUuid}
visitFormOpenedFrom={openedFrom}
setVisitFormCallbacks={setVisitFormCallbacks}

visitFormCallbacksRef={visitFormCallbacksRef} // Pass the ref instead
Copy link
Contributor

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.

Copy link
Author

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..!

@brandones
Copy link
Contributor

Please add a video demonstrating that everything still behaves as expected.

@Bharath-K-Shetty
Copy link
Author

Hey @brandones,I’ve made the changes as requested and updated the PR. Let me know if any further changes are needed.

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants