From cda50a5b36eea4be17fc151c739babd7e5c90a20 Mon Sep 17 00:00:00 2001 From: Josh Kelley Date: Thu, 11 Jun 2020 04:02:11 -0400 Subject: [PATCH] Update docs to explain dependent fetching with falsy (#449) * Update docs to explain dependent fetching with falsy This doesn't appear to be well documented. (See #426.) * Update README.md Co-authored-by: Shu Ding Co-authored-by: Shu Ding --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cb6791524..2385e0942 100644 --- a/README.md +++ b/README.md @@ -250,10 +250,11 @@ SWR also allows you to fetch data that depends on other data. It ensures the max function MyProjects () { const { data: user } = useSWR('/api/user') const { data: projects } = useSWR(() => '/api/projects?uid=' + user.id) - // When passing a function, SWR will use the - // return value as `key`. If the function throws, - // SWR will know that some dependencies are not - // ready. In this case it is `user`. + // When passing a function, SWR will use the return + // value as `key`. If the function throws or returns + // falsy, SWR will know that some dependencies are not + // ready. In this case `user.id` throws when `user` + // isn't loaded. if (!projects) return 'loading...' return 'You have ' + projects.length + ' projects'