Hello,
I'm using redux-offline and I would like to use redux-toolkit but the problem is redux-offline use a special keyword (offline) in the action object and this is ignored from redux-toolkit.
Is there a workaround for this ?
For the moment, I recreate the createAction function to allow offline object.
Thanks for your work !
If you need to set meta.offline, you can use the prepare callback notation:
createAction('test', (x: string) => ({ payload: x, meta: { offline: { /*... */}} }));
Something similar is available for createSlice if you need it, just take a look at the docs :)
Oh my bad ! I miss-used redux-offline, sorry for the issue !
Thanks for your quick answer, have a good day 馃槂
Sorry to comment on a closed thread, but in the above example, how do you create the reducer for that action?
That action could presumably have a few different actions types: Commit, Rollback and the initial action. I've been struggling all day with creating a reducer and haven't found any documentation.
@phryneas Could you give me an example about how to add offline object to createSlice?
@nguyenhoanglam
const todosSlice = createSlice({
name: 'todos',
initialState: [],
reducers: {
addTodo: {
reducer: (state, action) => {
state.push(action.payload)
},
prepare: (text) => {
return { payload: text, meta: { offline: ... } }
},
},
},
})
Most helpful comment
@nguyenhoanglam