Skip to content

Question regarding behavior of generator based components #84

Answered by lazeebee
mcjazzyfunky asked this question in General
Discussion options

You must be logged in to vote

If you change the loader component in the Crank example to the following then it will behave like the React example.

async function* Loader() {
  let rendered = false;
  for await (const { loadingText = 'Loading...', finishText = 'Finished!' } of this) { 
    yield <div>{loadingText}</div>
    if (!rendered) await wait(4000)
    yield <div>{finishText}</div>
    rendered = true;
  }
}

The reason for this, in the React example the usePromise hook runs only on the first render as it has a dependency array, so when the component refreshes, it doesn't run the promise again so it doesn't set the loading text again. But in the Crank example the promise is executed each time, so in the above cod…

Replies: 4 comments 13 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by brainkim
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
13 replies
@lazeebee
Comment options

@mcjazzyfunky
Comment options

@mcjazzyfunky
Comment options

@brainkim
Comment options

@mcjazzyfunky
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants
Converted from issue

This discussion was converted from issue #84 on April 30, 2020 18:13.