React-Redux - No reducer provided for key “coins”

后端 未结 4 1232
天命终不由人
天命终不由人 2020-12-30 19:05

Not sure why I\'m getting the following errors.

I\'m just setting up my store, actions and reducers, I haven\'t called dispatch on anything yet.

Expected

相关标签:
4条回答
  • 2020-12-30 19:24

    Your issue lies with how you're importing your coins reducer:

    import { coins } from './coins'
    

    The latter tries to obtain a named export returned from the file in ./coins.

    You are not using any named exports only export default, therefore you just need to import the file as follows:

    import coins from './coins';
    

    Using the latter will result with the fact that coins will then contain the value of export default; which will be the coins reducer.

    0 讨论(0)
  • 2020-12-30 19:24

    Ah just found it, I was importing my coins reducer incorrectly...

    import { combineReducers } from 'redux'
    import coins from './coins' // because I have coins/index.js
    
    export default combineReducers({
        coins
    });
    

    instead of

    import { coins } from './coins'
    
    0 讨论(0)
  • 2020-12-30 19:29

    Even when all your imports are correctly imported, this can still happen for one other reason. Circular Dependency!

    In my case, this happeded because of a circular dependency in a file. I had two circular dependecy in the project that I created accedentally. Example: rootReducer.ts -> authSlice.ts -> rootReducer.ts.

    These dependencies are often not as easy to debug. I used this package to check for circular dependencies. Once the circular dependency was removed, all was well.

    0 讨论(0)
  • 2020-12-30 19:36

    This was my fix:

    import { combineReducers } from 'redux'
    import { coins } from './coins'
    
    export default combineReducers({
        coinsState: coins || (() => null) // By adding this I resolved it.
    });
    
    0 讨论(0)
提交回复
热议问题