I'm creating dogs list app using React Hooks and Firebase. There's a list of dogs, and this page will be a detail page of each dogs.
So far I've successfully fetched an object from firebase database. Now I'm trying to put that object in state using setDog()
const [dog, setDog] = useState([{ name: '', breed: '' }]);
useEffect(() => {
const db = firebase.firestore();
var docRef = db.collection("dogs").doc(id); // id is the one I click from dogs list
docRef.get()
.then(response => {
const newDog = response.data();
console.log("newDog", newDog); // Object {name: 'cookie', breed: 'beagle'}
setDog(newDog); // <- This doesn't work
})
}, [])
I can console.log the object, however setDog(newDog) doesn't work. How do I put the data in state?