From 1aa142896d3f08ba0299c69a9f588eea0d661c12 Mon Sep 17 00:00:00 2001 From: Josh Kelley Date: Wed, 10 Jun 2020 11:44:03 -0400 Subject: [PATCH 1/2] Update docs to explain dependent fetching with falsy This doesn't appear to be well documented. (See #426.) --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index cb6791524..d5cd7eef3 100644 --- a/README.md +++ b/README.md @@ -250,10 +250,10 @@ 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 ready. In this case it is `user`. if (!projects) return 'loading...' return 'You have ' + projects.length + ' projects' From 4c402b2e3b4a93ba09f6a06dbe344e992fb29cc0 Mon Sep 17 00:00:00 2001 From: Josh Kelley Date: Wed, 10 Jun 2020 12:01:10 -0400 Subject: [PATCH 2/2] Update README.md Co-authored-by: Shu Ding --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d5cd7eef3..2385e0942 100644 --- a/README.md +++ b/README.md @@ -253,7 +253,8 @@ function MyProjects () { // 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 ready. In this case it is `user`. + // ready. In this case `user.id` throws when `user` + // isn't loaded. if (!projects) return 'loading...' return 'You have ' + projects.length + ' projects'