[英]Conditional rendering error in react native
I have a problem when conditional rendering a component in react native. 有条件地在React Native中渲染组件时遇到问题。 it shows me this error message:
它显示了此错误消息:
JavascriptException: {"stack":"Error: failed to execute 'importScripts' on 'WorkerGlobalScope'
JavascriptException:{“ stack”:“错误:无法在'WorkerGlobalScope'上执行'importScripts'
And here's an example of my code principe 这是我的代码原理示例
export default class App extends Component {
render() {
return(
{this.customRender()}
);
}
customRender() {
var x = true;
if(x) {
return (<View />);
}
else return (<Text>False</Text>);
}
}
Guys i fixed the problem. 伙计们,我解决了这个问题。 First i disabled the Remote debugging, after that the error message changed and now it shows that i have a syntax error in the render method, precisely in the return, so i changed this:
首先,我禁用了远程调试,此后错误消息发生了变化,现在它表明我在render方法中有语法错误,确切地说是在返回中,因此我对此进行了更改:
return({this.customRender()});
to this 对此
return(this.customRender());
and now it works. 现在可以了。
One problem could have nothing to do with the code, but it is a result of your application using the bundled JS-File in development mode. 一个问题可能与代码无关,但这是您的应用程序在开发模式下使用捆绑的JS-File的结果。 You should use the packager for the development and the normal bundled files for production usage.
您应将打包程序用于开发,并将正常的捆绑文件用于生产。 You can open the web browser with the "--allow-file-access-from-files" flag to use the bundled version in the development setting.
您可以使用“ --allow-file-access-from-files”标志打开Web浏览器,以在开发设置中使用捆绑的版本。
Another possible problem could be the self-closing View
-Tag. 另一个可能的问题可能是自动关闭的
View
-Tag。
Check the packager log, it's likely that you have a syntax error somewhere in your code, probably something very simple like a missing comma. 检查打包程序日志,您的代码中可能存在语法错误,可能很简单,例如缺少逗号。 Run a linter on your code, it will help you find the error if the error message frmo the packager log isn't helpful.
在代码上运行lint,如果错误消息frmo打包程序日志没有帮助,它将帮助您找到错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.