我想从子组件中调用一个方法,按照这里的建议从父组件中调用子方法
但是,当子组件用react-redux的connect包裹起来时,它不起作用,如下例所示:
子组件
interface OwnProps {
style?: any;
}
interface ReduxStateProps {
category: string;
}
interface DispatchProps {
updateTimestamp: (timestamp: Date) => void;
}
type Props = ReduxStateProps & DispatchProps & OwnProps;
interface State {
timestamp?: Date;
}
class ChildComponent extends React.Component<Props, State> {
childMethod = () => {
console.log("I am the child");
};
render(){
<Text>Debug</Text>
}
}
function mapStateToProps(state: any): ReduxStateProps {
return {
category: state.menu.category
};
}
function mapDispatchToProps(dispatch: Dispatch<any>): DispatchProps {
return {
updateTimestamp: …Run Code Online (Sandbox Code Playgroud)