redux-orm: Selector is not running while orm state has changed
Currently using the following selector to get the data of a patient from the orm database:
export const patientSelector = createSelector(orm, ormSelector, hashSelector, (session, hash) => {
const patient = session.Patient.withId(hash);
const consultations = patient.consultations.count();
const therapies = patient.therapies.count();
return session.Patient.hasId(hash) ? {
...patient.ref,
totalConsultations: consultations,
totalTherapies: therapies
} : null;
});
But after I update a deeper property (patient.resources.medicalFiles) it does not recognize the change and the selector does not update to the new state, so the component does not re-render. Looking at the redux devtools you can see the state has changed.

Reducer
case ActionTypes.ADD_PATIENT_MEDICAL_FILE:
const resources = Patient.withId(payload.patient).ref.resources;
const medicalFiles = resources.medicalFiles || [];
medicalFiles.push({name: payload.name, url: payload.url})
Patient.withId(payload.patient).update({
resources: {
...resources,
medicalFiles: medicalFiles
}
});
break;
Any ideas about this?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 35
You can see this tweet
@nealoke
It’s up to you, but It’s better do not use hardcoded values - maybe someday you will decide to change modelName and you will have to refactor.
p.s.: modelName here is from definition:
I think I ran into the same issue. What I ended up doing (and this worked for me with my model, but may or may not work for you) - is I added lastUpdateAt property on the top level object (patient) in your case and every time I touched anything in the object, I change the timestamp on the object. I think that is what solved my problem. Not guarantees though 😃