From 78385264febc0fe2cb576e355f77e08fa10e1b79 Mon Sep 17 00:00:00 2001 From: tim Date: Tue, 23 Jun 2020 16:10:12 -0400 Subject: [PATCH] fixed initialization bug for useEffect --- client/components/Housing.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/client/components/Housing.js b/client/components/Housing.js index 33bb0db6..c67f46a5 100644 --- a/client/components/Housing.js +++ b/client/components/Housing.js @@ -23,13 +23,14 @@ export default function Housing({ route, navigation }) { const [apts, setApts] = useState([fakeItem]) - const { getItem, setItem } = useAsyncStorage('counter'); + const { getItem, setItem } = useAsyncStorage('apts0'); const readItemFromStorage = async () => { try { let item = await getItem(); //item = item || JSON.stringify(fakeItem) - const newValue = JSON.parse(item); + let newValue = JSON.parse(item); + newValue = newValue || [fakeItem] setApts(newValue); } catch(e) { @@ -62,8 +63,8 @@ export default function Housing({ route, navigation }) { return( - apts.length = {apts.length} - apts[0] = {JSON.stringify(apts[0])} + apts.length = {apts && apts.length} +