A simpler and faster way to monitor redux-toolkit
actions. This way, no other libraries or extra configurations are needed; I just modified the dispatch
of the store
to also generate logs in reactotron
.
Before you start, you'll need to have the following libraries installed in your project:
Within your store
, simply configure it as follows:
import {configureStore} from '@reduxjs/toolkit';
import auth from './auth'; // your redux slice here
import reactotron from 'reactotron-react-native';
export const store = configureStore({
reducer: {
auth,
},
});
const next = store.dispatch;
store.dispatch = function dispatchAndLog(action: any) {
const PREV_STATE = store.getState();
let result = next(action);
const NEXT_STATE = store.getState();
reactotron.stateActionComplete(action.type, {
PREV_STATE,
NEXT_STATE,
PAYLOAD: action.payload,
});
return result;
};