Conditional rendering error in react native

我与影子孤独终老i 提交于 2019-12-12 04:34:08

问题


I have a problem when conditional rendering a component in react native. it shows me this error message:

JavascriptException: {"stack":"Error: failed to execute 'importScripts' on 'WorkerGlobalScope'

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>);
  }

}

回答1:


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:

return({this.customRender()});

to this

return(this.customRender());

and now it works.




回答2:


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. 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.

Another possible problem could be the self-closing View-Tag.




回答3:


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.



来源:https://stackoverflow.com/questions/41088268/conditional-rendering-error-in-react-native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!