From 9dfb61b78996fe7cfe7bb80b7921b8cfbb623d2e Mon Sep 17 00:00:00 2001 From: Lee Date: Wed, 13 May 2020 10:39:18 -0600 Subject: [PATCH 1/2] Step 7: cats on click --- src/App.js | 4 +++- src/hooks/catApi.js | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/App.js b/src/App.js index bf8aeef..636d302 100644 --- a/src/App.js +++ b/src/App.js @@ -11,12 +11,14 @@ function App() { const title = useSetTitle(count) - const {data, loading} = useCatApi() + const {data, loading} = useCatApi(count) return (
logo + +

{loading ? 'Loading Cats' : 'This is ameowzing!'}

Edit src/App.js and save to reload.

diff --git a/src/hooks/catApi.js b/src/hooks/catApi.js index 81e1029..0e5ad03 100644 --- a/src/hooks/catApi.js +++ b/src/hooks/catApi.js @@ -1,7 +1,7 @@ import {useEffect, useState} from 'react'; // This is using the cat api -function useCatApi() { +function useCatApi(count) { const [loading, setLoading] = useState(false); const [data, setData] = useState(null) useEffect(()=>{ @@ -16,7 +16,9 @@ function useCatApi() { setLoading(false); } getCats() - },[]) +// !IMPORTANT - deps if no defined it will run on every render, if empty it runs on init only, other wise it watches value +// \/ + },[count]) return {loading, data}; } From 00e7db8effc417f35984d41641cbcd5404c01ac8 Mon Sep 17 00:00:00 2001 From: Lee Date: Wed, 13 May 2020 10:46:23 -0600 Subject: [PATCH 2/2] fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 672f01b..04d071e 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Basic React Hooks lunch and learn -## From BERERK [Denver, Colorado's Javascript Pros BERZERK](http://www.BERZERK.io) +## From BERZERK [Denver, Colorado's Javascript Pros BERZERK](http://www.BERZERK.io) This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).