a way to change sortComparer in entityAdapter? #1356
-
Hi! :) const adapter = createEntityAdapter({
selectId: (itemList) => itemList.id,
sortComparer: (a, b) => a.createdAt - b.createdAt;
});
const slice = createSlice({
name: 'test',
initialState: adapter.getInitialState(),
reducers: {
changeOrder: (state, action) => {
chatInfosAdapter.sortComparer = (a, b) => b.createdAt - a.createdAt;
},
},
} I wanted to test this before I apply more complex sort comparer logic in entityAdapter. btw, i am also trying out rtk-query and loving it so far! cant wait for ssr support 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Not possible at the moment, sorry.
You could in theory create more than one adapter with different sorting methods, and switch which one you're using: if (someCondition) {
sortByNameAdapter.upsertOne(state, action)
} else {
sortByDateAdapter.upsertOne(state, action)
} |
Beta Was this translation helpful? Give feedback.
Not possible at the moment, sorry.
createEntityAdapter
creates a closure, and there's currently no way to change the sorting behavior after creation.You could in theory create more than one adapter with different sorting methods, and switch which one you're using: