1
我使用reselect和denormalizr來避免在每次更改時反規範化,但我不確定這是否真的改善了某些事情。將denormalizr與reselect結合使用是一種好方法嗎?
import { createSelector } from 'reselect'
import { denormalize } from 'denormalizr'
import { challenge as schema } from './challenge.schema'
const getState = (state) => state
export const getChallenge = createSelector(getState, ({ entities, challenge }) => {
return denormalize(entities.challenges[challenge.item], entities, schema)
})
export const getChallenges = createSelector(getState, ({ entities, challenge }) => {
return challenge.items.map((id) => denormalize(entities.challenges[id], entities, schema))
})