0
Answered

React Components

codeCaveMan 6 years ago in iPad updated by Alexander Blach (Developer) 6 years ago 3

Does Textastic support es6 modules? 

If so, I’m struggling to get it working in the app. 

Specifically, I’d like to keep my React js components in separate files and import them where needed. Please assist. 

Thanks.

Errol

GOOD, I'M SATISFIED
Satisfaction mark by codeCaveMan 6 years ago
Under review

Hello,

I assume you are talking about the web preview. Textastic uses a standard web view that uses the same WebKit engine as Safari. So, the web preview should support everything that is supported by Safari.

I tried a simple example I found at https://jakearchibald.com/2017/es-modules-in-browsers/ and it worked:

module.html:

<!doctype html>   
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>Test</title>
  
  <script type="module">
    import {addTextToBody} from './utils.js';

    addTextToBody('Modules are pretty cool.');
   </script>
</head>
<body>
  
</body>
</html>

utils.js:

export function addTextToBody(text) {
  const div = document.createElement('div');
  div.textContent = text;
  document.body.appendChild(div);
}

If I preview module.html in Textastic by tapping the "glasses" icon, it shows the message "Modules are pretty cool.". 

Brilliant! Works a treat! Thanks for your help Alexander.