Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I fix React.js iOS blank screen?

All my React.js apps work perfectly in all desktop browsers I have tested (chrome, edge, IE, firefox). However, when I try to open them on my iphone, either chrome or safari, I am presented with a blank screen.

Below is an example of an app that works on desktop but appears blank on iOS.

<html>
  <head>
    <meta charset="utf-8">

    <title>react test</title>

    <script src="js/jquery.min.js"></script>
    <script src="js/react.js"></script>
    <script src="js/react-dom.js"></script>

    <script>
      var h = React.createElement;

      $(document).ready(() => {
        ReactDOM.render(h('h1', null, 'Hello World!'), document.getElementById('app'));
      });
    </script>
  </head>
  <body>
    <div id="app"></div>
  </body>
</html>

What is the solution to this?

like image 776
Daniel Fearn Avatar asked Mar 06 '26 22:03

Daniel Fearn


1 Answers

I solved this one with a lot of experimentation.

The version of safari on my iphone did not support ES6 arrow functions which I used in my code.

Replacing all arrow functions with function(){} fixed the issue.

like image 90
Daniel Fearn Avatar answered Mar 09 '26 12:03

Daniel Fearn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!