Skip to content

Commit cda50a5

Browse files
joshkelshuding
andauthored
Update docs to explain dependent fetching with falsy (vercel#449)
* Update docs to explain dependent fetching with falsy This doesn't appear to be well documented. (See vercel#426.) * Update README.md Co-authored-by: Shu Ding <[email protected]> Co-authored-by: Shu Ding <[email protected]>
1 parent b7891a0 commit cda50a5

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,11 @@ SWR also allows you to fetch data that depends on other data. It ensures the max
250250
function MyProjects () {
251251
const { data: user } = useSWR('/api/user')
252252
const { data: projects } = useSWR(() => '/api/projects?uid=' + user.id)
253-
// When passing a function, SWR will use the
254-
// return value as `key`. If the function throws,
255-
// SWR will know that some dependencies are not
256-
// ready. In this case it is `user`.
253+
// When passing a function, SWR will use the return
254+
// value as `key`. If the function throws or returns
255+
// falsy, SWR will know that some dependencies are not
256+
// ready. In this case `user.id` throws when `user`
257+
// isn't loaded.
257258

258259
if (!projects) return 'loading...'
259260
return 'You have ' + projects.length + ' projects'

0 commit comments

Comments
 (0)