Добрый вечер.
Есть такой компонент :
// @flow
import * as React from "react";
import { connect } from "react-redux";
import { searchAction, changeMode } from "../../actions";
import SearchForm from "../../presentational/SearchForm";
type State = {
inputValue: string
};
type Props = {
searchAction: (inputValue?: string) => mixed,
changeMode: (val?: string) => mixed
};
class Search extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
inputValue: ""
};
}
handleSubmit = (e: SyntheticEvent<>) => {
e.preventDefault();
let { inputValue } = this.state;
this.props.searchAction(inputValue);
};
handleRadioChange = (e: SyntheticInputEvent<>) => {
this.props.changeMode(e.target.value);
};
inputHandle = (e: SyntheticInputEvent<>) => {
this.setState({ inputValue: e.target.value });
};
render() {
return (
<SearchForm
title="NASA Search"
inputHandle={this.inputHandle}
radioChangeHandle={this.handleRadioChange}
submitHandle={this.handleSubmit}
/>
);
}
}
function mapStateToProps(state) {
return {};
}
const mapDispatchToProps = {
searchAction,
changeMode
};
export default connect(mapStateToProps, mapDispatchToProps)(Search);
Ошибки возникают в трех местах :
inputHandle={this.inputHandle}
radioChangeHandle={this.handleRadioChange}
submitHandle={this.handleSubmit}
Код :
Cannot create `SearchForm` element because `SyntheticInputEvent` [1] is incompatible with string [2] in the first argument of property `inputHandle`.
Как это по-фиксить?
UPD: SearchForm.js :
//@flow
import React from "react";
type Props = {
title: string,
inputHandle: (value: string) => mixed,
radioChangeHandle: (value: string) => mixed,
submitHandle: (value: string) => mixed
};
const SearchForm = ({
title,
inputHandle,
radioChangeHandle,
submitHandle
}: Props) => {
return (
<div>
<h1>{title}</h1>
<form action="#" id="search-form">
<input type="text" id="searchInput" onChange={inputHandle} />
<input
type="radio"
name="radio-button"
value="image"
defaultChecked={true}
onChange={radioChangeHandle}
/>{" "}
Image
<input
type="radio"
name="radio-button"
value="video"
onChange={radioChangeHandle}
/>{" "}
Video
<input type="submit" value="Go" onClick={submitHandle} />
</form>
</div>
);
};
export default SearchForm;
GITHUB