davnicwil / react-frontload

Async data loading for React components, on client & server
451 stars 21 forks source link

Missing `await` in docs code example #51

Closed geophree closed 3 years ago

geophree commented 3 years ago

In the docs, I think you're missing an await before the Promise.all in the following code example:

const { data, frontloadMeta } = useFrontload('my-component', async ({ api }) => {
  const [stuff, moreStuff] = Promise.all([
    api.getStuff(),
    api.getMoreStuff()
  ])

  return { stuff, moreStuff }
})

should be:

const { data, frontloadMeta } = useFrontload('my-component', async ({ api }) => {
  const [stuff, moreStuff] = await Promise.all([
    api.getStuff(),
    api.getMoreStuff()
  ])

  return { stuff, moreStuff }
})

I looked for a documentation repo to PR, but couldn't find one.

Also, you may want to make it more obvious that the current docs are v2 in the callout that says:

v2 has just shipped! See here for the motivation for v2 and comparison with v1

Maybe something like:

These are the (just shipped) v2 docs! See here for the motivation for v2 and comparison with v1
davnicwil commented 3 years ago

Hey Jeff - great catches, thanks for this. I'll make both changes.

[edit: previously suggested a PR for a contribution credit before realising docs are of course not in this repo. I'll have a think about how to best combine the two so changes like this can be more easily PRd & tracked]

geophree commented 3 years ago

I don't need the credit, but feel free to mention me in the commit if you'd like.