Skip to content

Commit

Permalink
fix: use createSelector to avoid redux selector warning (#733)
Browse files Browse the repository at this point in the history
Rewrite selectDepthDependentData to use createSelector rather than chaining selectors inline. The selectDepthDependentData selector was causing a warning because of its internal use of selectSoilData. Redux recommends using the createSelector wrapper when chaining selectors together to avoid unnecessary re-renders.
  • Loading branch information
tm-ruxandra authored Jul 11, 2024
1 parent 3f9b955 commit e1b4e4d
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,18 @@ export const useSiteSoilIntervals = (siteId: string): AggregatedInterval[] => {
);
};

export const selectDepthDependentData =
({
siteId,
depthInterval,
}: {
siteId: string;
depthInterval: { depthInterval: DepthInterval };
}) =>
(state: SharedState): DepthDependentSoilData =>
selectSoilData(siteId)(state).depthDependentData.find(
sameDepth(depthInterval),
) ?? { depthInterval: depthInterval.depthInterval };
export const selectDepthDependentData = ({
siteId,
depthInterval,
}: {
siteId: string;
depthInterval: { depthInterval: DepthInterval };
}): ((state: SharedState) => DepthDependentSoilData) =>
createSelector(
selectSoilData(siteId),
soilData =>
soilData.depthDependentData.find(sameDepth(depthInterval)) ??
({
depthInterval: depthInterval.depthInterval,
} as DepthDependentSoilData),
);

0 comments on commit e1b4e4d

Please sign in to comment.