From 851972304d2133d8f30bb0b5cf26a7e72888e26f Mon Sep 17 00:00:00 2001 From: Max <ḿax.seyfried@gmx.de> Date: Sat, 11 Jul 2020 11:06:33 +0200 Subject: [PATCH] added comment to use effect for fetching data --- imports/ui/Home.jsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/imports/ui/Home.jsx b/imports/ui/Home.jsx index a7868c6..10540ed 100644 --- a/imports/ui/Home.jsx +++ b/imports/ui/Home.jsx @@ -18,13 +18,14 @@ export default function Home(props) { const [sensorCardValues, setSensorCardValues] = useState(updateCardValues); const [dataHistory, setDataHistory] = useState(props.dummyData); // for init data - // runs when the app mounts + // runs when the app mounts, similiar to componentDidMount and componentDidUpdate // if you give a prop to useEffect, it also runs each time this prop changes.. useEffect(() => { + // const data = await fetch('api-address') // fetch data from db here and destructure it console.log("data is changing, start rerender..") setDataHistory(props.dummyData); setSensorCardValues(updateCardValues); - }, [props.dummyData]) + }, []) // render the data // make sensorCarddeck responsive