Navigation Menu

Skip to content

Commit

Permalink
fixed initialization bug for useEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
tjhickey724 committed Jun 23, 2020
1 parent b864b5f commit 7838526
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions client/components/Housing.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -62,8 +63,8 @@ export default function Housing({ route, navigation }) {

return(
<ImageBackground source={background} style={styles.backgroundImage}>
<Text> apts.length = {apts.length}
apts[0] = {JSON.stringify(apts[0])}
<Text> apts.length = {apts && apts.length}

</Text>
<View style = {styles.container}>
<Modal visible={modalOpen} animationType='slide'>
Expand Down

0 comments on commit 7838526

Please sign in to comment.