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