I am fetching a list of objects from a database, but it is not saving the items in state.
when i logged the individual properties they show, but when i try to log allProperties before the return statement, it is empty
const getAllProperties = () => {
const propertyRef = ref(database, "properties");
const getProperties = async () => (await get(propertyRef)).val();
const [allProperties, setAllProperties] = useState([]);
getProperties().then((properties) => {
Object.values(properties).forEach((property) => {
setAllProperties([property]);
// console.log(property);
});
});
console.log(allProperties);
return allProperties;
};