useEffect
The Effect Hook lets you perform side effects in function components:
Function Component
import React, { useState, useEffect } from 'react';
import { Box } from "@chakra-ui/react";
function Example() {
const [property, setProperty] = useState([]);
const getDataProperty = async () => {
{let arr = [];
const q = collection(db, "property")
const querySnapshot = await getDocs(q);
querySnapshot.forEach((doc) => {
arr.push(doc.data());
});
console.log(arr, 'ini get data property di app bar dashboard')
setProperty(arr);} // example data
};
useEffect(() => {
getDataProperty([]) // for getData
return () => {
setProperty([])
}
}, [])
return (
<Box>
{property}
</Box>
);
}