未捕获的TypeError:(0,_reactRedux.bindActionCreators)不是一个功能

时间:2016-09-23 07:32:11

标签: reactjs redux

我正在玩redux,我已经开始得到这个错误,无法解决它,我希望它有任何意义,但似乎无法找到任何信息..任何人都可以解释原因这可能表明?感谢..

代码:

type M[X] = Int

包json:

import React, { Component } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'react-redux';
import  { searchForBeers } from '../../actions/index';


class SearchBar extends Component {

  constructor(props) {
    super(props);

    this.state = { term: ''}

    this.onFieldChange = this.onFieldChange.bind(this);
    this.onClickSearch = this.onClickSearch.bind(this);
  }

  onFieldChange(event) {
    this.setState({ term: event.target.value })

    console.log(this.state)
  }

  onClickSearch() {
    console.log(this.state)

    this.props.searchForBeers(this.state.term)
  }

  render() {
    return (
        <div className="col-lg-6" style={{top:20 , width:'70%'}}>
           <div className="input-group">
         <span className="input-group-btn">
           <button onClick={this.onClickSearch} className="btn btn-secondary" type="button">Go!</button>
         </span>
         <input type="text" className="form-control" placeholder="Search for..." onChange={this.onFieldChange} />
       </div>
       </div>
    )
  }

}

//Container functions

function mapDispatchToProps(dispatch) {
  return bindActionCreators({ searchForBeers }, dispatch);
}

export default connect(null, mapDispatchToProps)(SearchBar);

1 个答案:

答案 0 :(得分:13)

它是提供bindActionCreators功能的redux模块,因此导入它的正确方法是

import { bindActionCreators } from 'redux';

而不是从react-redux导入。

在他们的API文档网站docs上有一个包含示例的页面。

您看到的错误看起来很简单,因为babel转换ES2015模块的方式,但实际上React或Redux并没有抛出它。