首页 > 解决方案 > 在 React Native 中推送到另一个屏幕时必须使用解构道具分配

问题描述

我正在尝试在 React Native 中从登录屏幕导航到仪表板屏幕。

但是,它会引发以下错误。

Must use destructuring props assignment [react/destructuring-assignment]

我的代码是

loginMethod() {
//some code
if (Success) {
          this.props.navigator.push({
            Component: Dashboard
          });
        this.state.props.navigator.immediatelyResetRouteStack([{
      Component: Dashboard
    }]);

}

}

我对 React Native 很陌生,有什么建议吗?

标签: reactjsreact-nativepushnavigator

解决方案


那是一个 ESLint 错误。您可以通过提取navigator到单独的变量来修复它。

loginMethod() {
  //some code
  if (Success) {
     const { navigator } = this.props;

     navigator.push({
        Component: Dashboard
     });
  }
}

这应该可以解决您的错误。


推荐阅读