react-live icon indicating copy to clipboard operation
react-live copied to clipboard

async/await support in live editor

Open forgo opened this issue 5 years ago • 4 comments

I'm not sure whether async functions should be working in the LiveEditor or not, but when I have that syntax, I get this error in the LiveError:

"SyntaxError: Unexpected identifier"

I couldn't find any documentation or issues regarding this.

EDIT:

It appears this works:

async function loop(next) {

But this syntax does not:

async next => {

forgo avatar May 20 '20 18:05 forgo

Could you provide a repro in Code Sandbox or paste a bit more code here for context? That would help me debug this!

sofiapoh avatar May 21 '20 12:05 sofiapoh

Hey @sofiapoh , I just ran into the same issue. Here is a simple example:

https://codesandbox.io/s/reactliveasyncarrowerror-r74e2?file=/src/App.js

wdcryer avatar Mar 04 '21 18:03 wdcryer

I would like to bump this topic since I have the same issue as @forgo, and really need the async/await support for the internal documentation project :( Does anyone resolve the issue?

jakub-zebrowski avatar Aug 24 '22 11:08 jakub-zebrowski

Can you try with [email protected]? The code sample above works fine pasted into the online demo: https://react-live.netlify.app/

(using:

() => {
  const foo = async() => {
    await new Promise(resolve => {
      setTimeout(resolve, 1000)
    });
  };

  return <>hi</>;
};

)

ryan-roemer avatar Aug 24 '22 19:08 ryan-roemer

@ryan-roemer Is 3.1.1 live? The latest on NPM is 2.4.1, and the example you're using there doesn't work on that version.

@tcc-sejohnson -- Ah! I think it's tagged react-live@next. Can you try that and let us know if that fixes things?

ryan-roemer avatar Oct 13 '22 22:10 ryan-roemer

@ryan-roemer Thanks for the quick response :) Yes, that does fix it -- yay! Is it just a prerelease version? Any idea when we can expect 3.1.1 to go live?

@tcc-sejohnson we've re-tagged react-live@latest to be 3.1.1 (thanks for the tag @gksander !)

ryan-roemer avatar Oct 18 '22 16:10 ryan-roemer