Reactjs 函数未传入参数-React Redux

Reactjs 函数未传入参数-React Redux,reactjs,redux,react-redux,Reactjs,Redux,React Redux,我有一个搜索组件,它可以在单击按钮时捕获值。我使用Redux进行状态管理,当我传入数据时,我会得到一个错误 import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { Typeahead } from 'react-bootstrap-typeahead'; import { searchInput } f

我有一个搜索组件,它可以在单击按钮时捕获值。我使用Redux进行状态管理,当我传入数据时,我会得到一个错误

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { Typeahead } from 'react-bootstrap-typeahead';
import { searchInput } from '../../actions/index';

class Search extends Component {
  constructor(props) {
    super(props);
    this.setRef = null;
  }

  onSearch = () => {
        const value = this.setRef.instanceRef.state.text;
        console.log(value);
        this.props.searchInput(value);
  };

  render() {

    return (
      <form className="filter-form form-inline" role="search">
        <div className="form-group searchBar">
          <label className="filter-label">Search:</label>
          <Typeahead
            bsSize={ 'sm' }
            options={ this.props.options }
            placeholder={ this.props.placeholder }
            emptyLabel={ this.props.emptyLabel }
            ref={ a => this.setRef = a }
          />
          <span
            role={ 'search' }
            className="glyphicon glyphicon-search filter-label"
            id="searchButton"
            onClick={ this.onSearch }
          />
        </div>
      </form>
    );
  }
}

Search.propTypes = {
  options: PropTypes.array,
  placeholder: PropTypes.string,
  emptyLabel: PropTypes.node,
};
Search.defaultProps = {
  options: ['red', 'green', 'blue', 'orange', 'yellow'],
  placeholder: 'Enter a placeholder',
  emptyLabel: null,
};

export default connect(null, searchInput)(Search);
这是我的减速机

import * as ACTION_TYPES from '../consts/action_types';

const initialState = {
  searchTerm: '',
};

export const searchReducer = (state = initialState, action) => {
  switch (action.type) {
    case ACTION_TYPES.SEARCH_INPUT:
      return {
        ...state,
        searchTerm: action.data,
      };
    default:
      return state;
  }
};
这就是我得到的错误

Uncaught TypeError: n.props.searchInput is not a function
    at n.onSearch (Search.js:16)
    at Object.R (react-dom.production.min.js:26)
    at Object.invokeGuardedCallback (react-dom.production.min.js:25)
    at Object.invokeGuardedCallbackAndCatchFirstError (react-dom.production.min.js:25)
    at $ (react-dom.production.min.js:30)
    at ee (react-dom.production.min.js:32)
    at ne (react-dom.production.min.js:32)
    at Array.forEach (<anonymous>)
    at Z (react-dom.production.min.js:31)
    at se (react-dom.production.min.js:34)
未捕获类型错误:n.props.searchInput不是函数
在n.onSearch(Search.js:16)
在Object.R(react dom.production.min.js:26)
在Object.invokeGuardedCallback(react dom.production.min.js:25)
在Object.invokeGuardedCallbackAndCatchFirstError处(react dom.production.min.js:25)
美元(react dom.production.min.js:30)
在ee(react dom.production.min.js:32)
在ne(react dom.production.min.js:32)
在Array.forEach()处
在Z处(react dom.production.min.js:31)
在se(react dom.production.min.js:34)

有人能指出我的错误吗?

我相信
connect
调用需要将对象中的分派函数传递给
mapDispatchToProps

export default connect(null, { searchInput })(Search);

我认为,
connect
调用需要将对象中的分派函数传递给
mapDispatchToProps

export default connect(null, { searchInput })(Search);

导出默认连接(null,{searchInput})(搜索)

导出默认连接(null,{searchInput})(搜索)

我的错。这就解决了问题。谢谢,我的错。这就解决了问题。谢谢