Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

firebase get last document

//using React
//Make sure to import and initialize your Firebase App
const firestore = firebase.firestore();
const collection = firestore.collection("myCollection");
const { documentData, setDocumentData } = useState({});

const getDocument = () => {
  collection.get()
  .then((snapshot) => {
    setDocumentData(snapshot[0].data());
  });
}

useEffect(() => {
	getDocument();
}, []);
 
PREVIOUS NEXT
Tagged: #firebase #document
ADD COMMENT
Topic
Name
1+7 =