Help me, please. I have got 2 reducers created with createSlice method of redux/toolkit.
user.reducer.js
import { createSlice } from '@reduxjs/toolkit';
const initialState = {
id: 123,
name: 'Owner123',
cats: [],
};
const reducer = createSlice({
name: 'user',
initialState,
reducers: {
addCat: (state, action) => {
state = {
...state,
cats: [...state.cats, action.payload],
};
return state;
},
feedCat: (state, action) => {
// call eat method from catReducer
},
},
});
export const { addCat, feedCat } = reducer.actions;
export const userReducer = reducer.reducer;
cat.reducer.js
import { createSlice } from '@reduxjs/toolkit';
const initialState = {
id: null,
name: null,
age: null,
color: null,
foodLevel: null,
healthLevel: null,
weight: null,
};
const reducer = createSlice({
name: 'cat',
initialState,
reducers: {
createCat: (
state,
{
payload: {
id,
name,
age,
color,
foodLevel,
healthLevel,
weight,
},
}
) => {
state = {
id: id,
name,
age,
color,
foodLevel,
healthLevel,
weight,
};
return state;
},
eat: (state, action) => {
console.log('hello from cat');
},
},
});
export const { createCat, eat } = reducer.actions;
export const catReducer = reducer.reducer;
My question is: How can I call a method from cat reducer within user reducer?
I have already tried some guides from StackOverflow like catReducer.caseReducers.eat(), but it does not work.