Hacker News new | ask | show | jobs
by acemarke 1843 days ago
You should be able to write thunks in the same file as `createSlice`, usually in front of the `createSlice` call, and then use the `extraReducers` "builder callback" syntax inside the slice to handle the various actions dispatched by the thunk. See the example here:

- https://redux-toolkit.js.org/usage/usage-with-typescript#typ...

And yeah, `createSelector` _is_ the Reselect API, just re-exported.

You might want to also take a look at our upcoming "RTK Query" API that will be in Redux Toolkit 1.6, which should be out in the next couple days. It's a data fetching and caching layer built specifically for Redux usage. The preview docs are here:

- https://deploy-preview-1016--redux-starter-kit-docs.netlify....

1 comments

Ah yes. We did end up using extraReducers, but didn’t love that the thunks and their corresponding reducers had to live in separate parts of the file. (For me at least, mentally simpler to have an action and it’s reducer close together.)

This looks cool, thanks for passing along! I’m actually starting a new project now, and deciding what my state management / caching layer should be, so great to know this is an option.