相关疑难解决方法(0)

无法使用带有连接的引用的子方法

我想从子组件中调用一个方法,按照这里的建议从父组件中调用子方法

但是,当子组件用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)

react-native react-redux

4
推荐指数
1
解决办法
747
查看次数

标签 统计

react-native ×1

react-redux ×1