ok so im incredibly new to redux (watched like 1 tutorial) i got the basic counter example working but now i am stuck trying to make a custom reducer
this is the reducer (yes it is in my store)
import { createSlice } from '@reduxjs/toolkit'
import type { PayloadAction } from '@reduxjs/toolkit'
import type { RootState } from '../store.ts'
import type { Module } from '../../assets/moduleList.tsx'
import modulesList from '../../assets/moduleList.tsx'
// Define the initial state using that type
const initialState: Module = modulesList[0];
export const currentModuleSlice = createSlice({
name: 'currentModule',
// `createSlice` will infer the state type from the `initialState` argument
initialState,
reducers: {
setCurrent: (state, action: PayloadAction<Module>) => {
state = action.payload
}
},
})
export const { setCurrent } = currentModuleSlice.actions
export default currentModuleSlice.reducer
and this is my code that should set it```html
<button
onClick={(e) => {
console.log(currentModule.name)
console.log(m.name)
dispatch(setCurrent(m)) // dispatch = useAppDispatch (for typescript types)
console.log(currentModule.name)
}}
>
{
m.iconPath ?
<img src={m.iconPath} alt="" />
: null
}
{m.name}
</button>
and the console output from this is ```
Tasks (Default)
Profiles (Clicked)
Tasks (Default)```