繁体   English   中英

减速器不被调用,甚至动作被调用

[英]reducer not getting called even action get callled

我尝试将更多道具添加到现有列表中,我可以执行调度操作,但reducer不会触发,我的headercontainer.js文件如下

    import React, { Component, PropTypes } from 'react'
    import { connect } from 'react-redux'
    import { fetchAccount } from 'actions/account'
    import { getAccount } from 'reducers/account'
    import { fetchCart } from 'actions/cart'
    import { getCart } from 'reducers/cart'
    //import * as cls from 'actions/cls'
    import { getReadmore } from 'reducers/cls'
    import * as cls from 'actions/cls'

    import { fetchAuthenticityToken } from 'actions/authenticityToken'
    import { getAuthenticityToken } from 'reducers/authenticityToken'
    import Header from 'components/Header'

    class HeaderContainer extends Component {
      static propTypes = {
        account: PropTypes.object,
        authenticityToken: PropTypes.object,
        cart: PropTypes.object,
          dispatch: PropTypes.func

      }

      componentDidMount() {
        if (typeof document !== 'undefined') {
          if (!this.props.account.isFetching) {
            this.props.dispatch(fetchAccount())
          }
          if (!this.props.authenticityToken.isFetching) {
            this.props.dispatch(fetchAuthenticityToken())
          }
          if (!this.props.cart.isFetching) {
            this.props.dispatch(fetchCart())
          }
        }
      }

       constructor(props) {
            super(props);

            this.state = {classToSend: true };
        }

        stateToRender(){
            (this.state.classToSend) ? this.setState({classToSend: false}) : this.setState({classToSend: true});
        }




        onClickHandler(){

            this.stateToRender();
            let action = cls.readMore(this.state.classToSend)
        this.props.dispatch(action)



            // this.props.readMore(this.state.classToSend);
        }


      render() {
        const { account, cart, authenticityToken } = this.props

        if(!account || !cart) {
          return false
        }

        return (
            <div id ="cvb">
          <div id="toggle-nav" className={this.state.toggleClass?'visible-xs nav-open':'visible-xs'} onClick={() => this.onClickHandler()} >
          <span data-action="toggle-nav" className="action mt-menu-label">
            <span className="mt-menu-bread mt-menu-bread-top">
              <span className="mt-menu-bread-crust mt-menu-bread-crust-top"></span>
            </span>
            <span className="mt-menu-bread mt-menu-bread-middle">
              <span className="mt-menu-bread-crust mt-menu-bread-crust-middle"></span>
            </span>
            <span className="mt-menu-bread mt-menu-bread-bottom">
              <span className="mt-menu-bread-crust mt-menu-bread-crust-bottom"></span>
            </span>
          </span>
        </div> 

          <Header account={account} cart={cart} />
          </div>
        )
      }
    }

    const mapStateToProps = (state) => {
      return {
        account: getAccount(state),
        cart: getCart(state),
        classToSend: getReadmore(state),
        authenticityToken: getAuthenticityToken(state)
      }
    }

    export default connect(mapStateToProps)(HeaderContainer)

我的cls.js减速器

export function getReadmore(state) {
console.log(state.readMore1)
console.log("are yar")
return state.readMore1
}

export  function readMore1 (state="", action) {
console.log(action.type)
 switch(action.type){

    case READ_MORE:

        return action.payload;
}

return state;
}

cls.js动作

export function readMore(class_something) {


const READ_MORE = 'READ_MORE';

    console.log("--------------------------")
    console.log(class_something)

    return {
        type: READ_MORE,
        payload: class_something
    };

}

虽然我可以调用动作cls.js文件,但是reducer没有触发,任何人都可以帮助我摆脱这种麻烦。

我的编辑

我在reducer文件夹中的index.js

import { combineReducers } from 'redux'
import { reducer as form } from 'redux-form'
import { routerReducer } from 'react-router-redux'
import { currency } from './currency'
import { cart } from './cart'
import { account } from './account'
import { alerts } from './alerts'
import { login } from './login'
import { authenticityToken } from './authenticityToken'
import { products } from './products'
import { product } from './product'

const routing = routerReducer

const rootReducer = combineReducers({
  form,
  routing,
  currency,
  cart,
  cls,
  account,
  alerts,
  authenticityToken,
  login,
  products,
  product
})

export default rootReducer

减速器文件中的大小写应为“ READ_MORE”(带引号),而不是READ_MORE(不带引号)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM