Data from a server is derived from its inputs too: the user to show depends on the selected id. So it is written the same way, as a memo, except the memo returns a promise:
const user = createMemo(() => fetchUser(userId()));Readers call user() as usual and get the user, not a promise. Until the first answer arrives there is nothing to show, so the nearest Loading boundary shows its fallback; the next lesson covers boundaries.
When userId changes, the memo asks again. The old user stays on screen until the new one arrives, and an answer for an id you've already moved past is never shown. The starter's isPending(user) marks that wait; a later lesson covers it.
Read every signal before the first await in an async function. Reads after it aren't tracked.
Try it: the memo returns a placeholder object. Return fetchUser(userId()) instead, then change the id.
Loading editor…