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

useResource updates when updateResource is called #4698

Open
rahul1 opened this issue Jun 19, 2024 · 1 comment
Open

useResource updates when updateResource is called #4698

rahul1 opened this issue Jun 19, 2024 · 1 comment

Comments

@rahul1
Copy link
Member

rahul1 commented Jun 19, 2024

consider this snippet

const patient = useResource(patientRef); 

return (
   <h1> {patient.name[0]} </h1>
   <button onclick={()=>
              medplum.updateResource({
              ...patient, 
              name: [{given: 'foo'}]
              }>Change Name</button>
)

After the updateResource is performed, the MedplumClient receives the response with the new Patient, but the useResource hook does not re-render.

This limits the usefulness of the hook, as you then have to drop down to useEffect

@ThatOneBro
Copy link
Member

Proposed solution:

MedplumClient emits resource lifecycle events:

  • resourceCreated
  • resourceUpdated
  • resourceDeleted

Then the useResource hook can rerender based on receiving resourceUpdated and resourceDeleted

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

No branches or pull requests

2 participants