reactjs redux“无法读取属性'isfetching'of undefined”

时间:2017-02-17 08:38:24

标签: reactjs redux

我创建新的redux存储和操作,但它显示错误

  

无法读取未定义

的属性isFetching

我的代码是:

store.js

import * as ActionTypes from '../actions/secone'

const productBrand = (state={records:[], isFetching: false}, action) => {
    switch (action.type) {
        case ActionTypes.PRODUCT_BRAND_REQUEST:
        return { ...state, isFetching: true}
    case ActionTypes.PRODUCT_BRAND_SUCCESS:
    default:
        return state;
    }
}
export default productBrand

action.js

import { CALL_API } from '../middlewares/api'

export const PRODUCT_BRAND_REQUEST = 'PRODUCT_BRAND_REQUEST'
export const PRODUCT_BRAND_SUCCESS = 'PRODUCT_BRAND_SUCCESS'
export const PRODUCT_BRAND_FAILURE = 'PRODUCT_BRAND_FAILURE'

export const fetchProductBrand = () => (dispatch, getState) =>  {
    if (!getState().productBrand.isFetching) {
        dispatch({
            [CALL_API]: {
                types: [ PRODUCT_BRAND_REQUEST,PRODUCT_BRAND_SUCCESS,PRODUCT_BRAND_FAILURE ],
            endpoint: 'productbrand'
            }
        })
    }
}

component.js

class SecOne extends Component {

componentWillMount() {
    this.props.fetchProductBrand()
}

handleOnSubmit = (e) => {
        e.preventDefault();
        console.log(this.refs.brand.refs.searchTextField.input.value)
};

render() {

    const data = [];
    // const {productBrand} = this.props

    return (
        <div>
           <Tabs>
                <Tab icon={<Bike />} label="Motor" >
                    <div style={style.secOneField}>
                        <AutoComplete id="brand" ref="brand" floatingLabelText="Brand" dataSource={data} maxSearchResults={5} filter={AutoComplete.caseInsensitiveFilter} openOnFocus={true}/>
                        <RaisedButton label="Search" primary={true} onClick={this.handleOnSubmit}/>
                    </div>
                </Tab>
                <Tab icon={<Car />} label="Mobil">
                    <div>
                    </div>
                </Tab>
            </Tabs>
        </div>
    );
}
}

const mapStateToProps = (state, ownProps) => ({
     productBrand: state.productBrand.records
});

const mapDispatchToProps = (dispatch, ownProps) => ({
    fetchProductBrand: () => dispatch(fetchProductBrand())
});

export default connect(
    mapStateToProps,
    mapDispatchToProps
)(SecOne);

我不知道为什么没有检测到状态? productBrand:state.productBrand.records 未检测到此状态(已定义) 我的代码有问题吗?

0 个答案:

没有答案