Replies: 4 comments 14 replies
-
I always love reading through these. Great high-level context and detailed-enough descriptions!
What happens in the case the promise returned by |
Beta Was this translation helpful? Give feedback.
-
Just to confirm: This does mean we can't use |
Beta Was this translation helpful? Give feedback.
-
The RFC draft explains the pitfalls preventing client components from also being async/await, but doesn't really address why (despite making references to // Server
function* Note({id, isEditing}) {
// On the server, yielding a Promise could be
// equivalent to `await`
const note = yield db.posts.get(id);
return (
<div>
<h1>{note.title}</h1>
<section>{note.body}</section>
{isEditing ? <NoteEditor note={note} /> : null}
</div>
);
} // Client
function* Note({id}) {
// On the client, we can still yield a promise.
// Unlike await, React can potentially resolve this synchronously.
const note = yield fetchNote(id);
return (
<div>
<h1>{note.title}</h1>
<section>{note.body}</section>
</div>
);
} Here too, React's "replay" behavior becomes not the behavior of a magical function ( Furthermore, it would not require the potentially confusing change to the rules of hooks: you can use the Finally, even if the native generator runtime has untenable performance characteristics, I'm not sure there would be anything preventing a specialized React plugin from generating a more optimal representation if necessary. Note too that there is a lot of existing examples of generators being used for this sort of cooperative multitasking. I'm not (formally) suggesting this option at the moment, but I can see it being a relatively common question, so perhaps worth addressing as part of the RFC. |
Beta Was this translation helpful? Give feedback.
-
So, it's expected that other libraries/frameworks to set those fields to a promise object, before React handles it. Any caveats around it? (I'll follow this convention in one of my libs. Currently, it uses a symbol property.) |
Beta Was this translation helpful? Give feedback.
-
This proposal has been opened as a public RFC. Please leave additional feedback in the main discussion: reactjs/rfcs#229
Previous iterations of the proposal are available in the edit history of this description.
Beta Was this translation helpful? Give feedback.
All reactions