javascript - 将回调函数传递给子组件,不是函数错误
问题描述
_videos.filteredVideo) is not a function
当我尝试从子组件分派操作时出现错误。如何将一个传递action
给我的子组件?
我有这个容器组件:
class SearchScreen extends React.Component {
filterVideo = payload => {
filteredVideo(payload);
};
render() {
return (
<View style={styles.container}>
<Search {...this.props} filterVideo={this.filterVideo} />
</View>
);
}
}
const mapDispatchToProps = dispatch => ({
filteredVideo: () => dispatch(filteredVideo())
});
const mapStateToProps = state => {
return {
videos: state.videos
};
};
export default connect(
mapStateToProps,
mapDispatchToProps
)(SearchScreen);
子组件:
filteredVideo = filteredData => {
const { filterVideo } = this.props;
filterVideo(filteredData); //_videos.filteredVideo) is not a function
};
filterList = event => {
let videos = this.state.initialVideos;
let {
nativeEvent: { text }
} = event;
let filteredData = videos.filter(item =>
item.title.toLowerCase().includes(text.toLowerCase())
);
this.filteredVideo(filteredData);
};
解决方案
推荐阅读
- flowtype - 如何在函数中定义对象类型?
- android - 尝试在空对象引用上调用虚拟方法“void android.widget.Editor$InsertionPointCursorController.show()”
- php - 如何将视图模板存储到mysql数据库中
- async-await - 等待,它是如何工作的?
- android - 在 Android 7.0 版中未记录传出的语音
- ruby-on-rails - 使用 *_type? 方法 Rails 多态关联 | 导轨 5
- c# - File.Copy 适用于调试模式,但不适用于发布模式
- swift - 我如何将协议实现作为函数的参数
- visual-studio - 测试属性页中的 Visual Studio 2017 错误
- itext - 如何防止 TextSharp Pdftable 中的表头拆分