where is counterReducer from? #4403
Answered
by
markerikson
snowden-fu
asked this question in
Help
-
In official demo, I have noticed import { configureStore } from '@reduxjs/toolkit'
import counterReducer from '../features/counter/counterSlice'
export default configureStore({
reducer: {
counter: counterReducer
}
}) below is import { createSlice } from '@reduxjs/toolkit'
export const counterSlice = createSlice({
name: 'counter',
initialState: {
value: 0
},
reducers: {
increment: state => {
// Redux Toolkit allows us to write "mutating" logic in reducers. It
// doesn't actually mutate the state because it uses the immer library,
// which detects changes to a "draft state" and produces a brand new
// immutable state based off those changes
state.value += 1
},
decrement: state => {
state.value -= 1
},
incrementByAmount: (state, action) => {
state.value += action.payload
}
}
})
export const { increment, decrement, incrementByAmount } = counterSlice.actions
export default counterSlice.reducer |
Beta Was this translation helpful? Give feedback.
Answered by
markerikson
Aug 11, 2022
Replies: 1 comment
-
It's an ES module "default import/export". When you do In this case, I called it |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
snowden-fu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's an ES module "default import/export".
When you do
export default whatever
, another file can doimport AnyNameYouWantHere from "./some/other/file"
.In this case, I called it
counterReducer
, but I could have called itimport fred
orimport aldkfjalsdkflkasjdf
. It's just creating a variable name in the importing file.