reactjs - 在 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 很陌生,有什么建议吗?
解决方案
那是一个 ESLint 错误。您可以通过提取navigator
到单独的变量来修复它。
loginMethod() {
//some code
if (Success) {
const { navigator } = this.props;
navigator.push({
Component: Dashboard
});
}
}
这应该可以解决您的错误。
推荐阅读
- android - 删除旧地图标记并在集群管理器中加载新标记
- acumatica - 在 Acumatica 中为通用查询添加可点击链接
- php - 当值作为字符串返回时,在 PHP 中格式化日期
- reactjs - redux saga 如何在函数中触发 next
- html - go/golang 服务器中的静态 css 文件
- swift - 基于 3 个值的简单验证条件
- c# - 使用 SSL/TLS HTTPS 从 C# 启动轻量级 Web 服务器 - 无需安装证书/使用 netsh?
- php - codeigniter 3 php 7.2 count() 函数不起作用
- sql - Hive SQL 删除数组中的空元素
- python - 从 2d numpy 数组中提取旋转的 1d 轮廓的结果不一致