You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm curious how you think about conditional fetching since we can't use conditionals with React hooks. For example, say we have a storefront with a list of items. And if the current user has special access, each item will get augmented with a discount.
In totally invalid React pseudocode:
const {data: user} = userSWR(`/api/me`)
const {data: items} = useSWR(`/api/items`)
let discounts = []
if (user.isSpecial) {
const {data} = useSWR(`/api/discounts`)
if (data) { discounts = data }
}
return <ItemList items={items} discounts={discounts} />
Being able to pass fetch in gives us an escape hatch, but I'm not sure if that's how you intended it to be used.
Hey, thanks for putting together this library.
I'm curious how you think about conditional fetching since we can't use conditionals with React hooks. For example, say we have a storefront with a list of items. And if the current user has special access, each item will get augmented with a discount.
In totally invalid React pseudocode:
Being able to pass
fetch
in gives us an escape hatch, but I'm not sure if that's how you intended it to be used.How would you go about implementing this pattern? Thanks!
The text was updated successfully, but these errors were encountered: