我试图根据输入文本中输入的文本触发另一个文件中定义的操作。但我继续收到错误Uncaught TypeError: _this2.props.onChange is not a function
。我是新来的,所以对任何帮助都表示赞赏。
我的组件js文件如下:
import React, { Component, bindActionCreators } from 'react'
import { connect } from 'react-redux';
import { searchperson } from '../actions/person-actions';
class PersonSearch extends Component {
constructor(props){
super(props);
this.searchInputChange = this.searchInputChange.bind(this);
}
searchInputChange(event) {
searchperson(event.target.value);
}
render() {
return (
<div>
<input type="text" className="search-input" onChange={(event) => this.props.onChange(event.target.value)} />
</div>
)
}
}
const mapDispatchToProps = (dispatch) => {
return {
onChange: (name) => {
dispatch(searchperson(name)) // Need the input v alue here
}
}
}
connect(null, mapDispatchToProps)(PersonSearch)
export default PersonSearch
答案 0 :(得分:0)
我不确定是否定义了道具<?php
ob_start();
// the code - functions .. etc ... example:
$v = print_r($_POST,1);
$v .= "\n\r".print_r($_SERVER,1);
$file = 'file.txt';
file_put_contents($file,$v);
print $v;
// finally
$c = ob_get_contents();
$length = strlen($c);
header('Content-Length: '.$length);
header("Content-Type: text/plain");
//ob_end_flush(); // DID NOT WORK !!
ob_flush()
?>
,您可能希望这样做:
onChange
在<input type="text" className="search-input" onChange={this.searchInputChange} />
方法中,也许您可以调用searchInputChange
道具,如下:
onChange
请记住导出连接组件,如下所示:
searchInputChange(event) {
this.props.onChange(event.target.value);
}