我在React中有一个带有onChange事件的组件.在下面的代码中,我需要声明在调用时调用正确的方法
this.props.onChangeImage()
Run Code Online (Sandbox Code Playgroud)
在Gallery组件中调用.
export class Form extends React.PureComponent {
componentDidMount = () => {
this.props.getUser();
this.props.getImages();
this.props.getBoards();
}
render() {
if (this.props.pin === null) {
let boards = [];
boards = this.props.boards;
boards = boards.data.map(
(item) => <MenuItem key={item.id.toString()} value={item.name} primaryText={item.name} />
);
return (
<div>
<Helmet
title="Form"
meta={[
{ name: 'description', content: 'Description of Form' },
]}
/>
<Gallery images={this.props.images} onChange={this.props.onChangeImage} />
</div>
);
}
return (<div className="spinner-container"><CircularProgress /></div>);
}
}
Run Code Online (Sandbox Code Playgroud)
下面,在onChangeImage方法中,我试图断言调用sendEventToParentWindow方法.
function mapDispatchToProps(dispatch) {
return {
onChangeImage: (event) …Run Code Online (Sandbox Code Playgroud)