Answer the question
In order to leave comments, you need to log in
Why does Flow complain about passing a function to a component?
Good evening.
There is this component:
// @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}
//@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;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question