我尝试用ref调用子函数,但是子函数有一个reduce函数,所以它确实有效:
我的父母:
search(data) {
this.SearchProduct.search(data);
}
...
<SearchProduct ref={instance => { this.SearchProduct = instance; }} />
我的孩子:
class SearchProduct extends React.Component {
...
search(data) {
console.log(data)
}
...
}
const mapStateToProps = (state, ownProps) => ({
basket: state.basket,
});
const mapDispatchToProps = (dispatch, ownProps) => ({
setBasket: (basket) => {
dispatch({ type: 'SET_BASKET', basket });
}
});
module.exports = connect(
mapStateToProps,
mapDispatchToProps,
null,
{ withRef: true }
)(SearchProduct);
当我解雇时:
component.js:25 Uncaught TypeError: this.SearchProduct.search is not a function
任何人都有想法?
非常感谢