I'm trying to save fetched data into variable, but I always get "too many rerenders" or "undefined". What I'm doing wrong
import {
child,
get,
getDatabase,
ref,
} from "firebase/database";
const db = getDatabase();
function App() {
const [data, setData] = useState();
const getData = ref(db);
useEffect(() => {
const fetch = () => {
get(child(getData, "tokens/")).then((snapshot) => {
const fetched = snapshot.val();
setData(fetched);
});
setTimeout(() => {
console.log(data);
}, 500);
};
fetch();
}, []);
}