score:3
Accepted answer
the following should do the trick:
import { collection, query, orderby, onsnapshot } from "firebase/firestore";
const id = ...;
const messagescolref = collection(db, "rooms", id, "comments");
const messagesquery = query(messagescolref, orderby("timestamp"));
onsnapshot(messagesquery, (snapshot) => {
setstate(snapshot.docs.map(doc =>
doc.data()))
});
have a look at the firestore reference.
score:0
related to your question indirectly, if you want to procrastinate and upgrade to 9 but leave your code as is, you can use the version 9 compat (compatibility) link. just replace your version 8 with version 9 and add "-compat" before ending '.js' .e.g.
<script src="https://www.gstatic.com/firebasejs/9.3.0/firebase-app-compat.js"></script>
this way don't change your code while using latest version of firebase. the disadvantage is that you won't benefit from module nature firebase 9.
Source: stackoverflow.com
Related Query
- How can i change this Firebase version 8 code to version 9
- How can I change this url to a link in that code when using ReactTable?
- how i can change this code to functional component in react
- How can I get webpack-dev-server to stop downloading incorrect chunks on content change with React lazy/Suspense code splitting?
- How can I simplify this redundant React code in the component?
- Why does my NextJS Code run multiple times, and how can this be avoided?
- How can I change the color of the circle of this MUI circular progress
- How and where can I add testid props to this code
- How can I use setInterval() to automatically change slides on this React Spring project
- How can I further improve this code to follow the standards?
- How can I make this work with less code and more efficiently? - Mapping Json and rendering components conditionally
- How can I change this Navbar dropdown item to update from "Login" to "Logout" when a user logs in?
- How can I run code on a route change from certain pages using react-router 5
- How do I convert this code from Firebase Firestore v8 to Firebase Firestore v9 Modular in React
- What can I change to make this code work with all section elements
- Uncaught (in promise) Error: Request failed with status code 400, How can I solve this error in React.js + Django App?
- refs is depreciated. refs works but is depreciated. How can we make this code work without using refs keyword here
- How can I use a button to change the Theme for material UI on my site? this is where I am so far
- How to refactor this code ?how can i make this code better?
- How can redirct a user to specific url based on his role in this react-redux code
- How can I implement the filter method to this code without deleting map method?
- how can I change the layout of this material UI form?
- How can I place a <dv> after a <Typography> in this code
- How can I change the position of this React component to fixed?
- How can i inject this piece of code in to a object value?
- How can I adapt this JS code to my Reactjs app so that I can customize my video player?
- How can I use firebase's language code (myFirebase.auth().languageCode) in my action link URL in Firebase Authentication email template?
- How can I make this element class change on scroll in React?
- How can I change npm version while using create-react-app
- How can i resolve the syntax error from this code
More Query from same tag
- React MUI partially collapsible grid sections
- Example of async with recompose()?
- How to switch between child routes?
- reactjs: execute a script only after render is complete after a certain part of state is changed
- React not able to setState from within a function
- Call method on ES6 class instance of React.Component
- How to change, using React, the value of a form input after clicking the submit button
- reactjs - anchor tag link
- Hide App Elements React
- multiple react state updates renders only the last update
- How to use react-routers in reactjs
- How do I define custom renderers for default Markdown elements using markdoc.io?
- e.target.value is undefined in reactjs
- Problem displaying PDF in React from UInt8Array (react-pdf)
- React setState inside script text content
- How to change the Redux state based on an Electron menu click?
- In React, how do I name a field of my form that is part of an array?
- rollup.js single import multiple usages
- reactjs not translating object and html
- How to sort object with numeric keys in descending order?
- ReactJS - Run useEffect only when third party library is fully loaded on the window object (Spotify SDK)
- Delete particular data in mongodb using node js
- How can i filter search result?
- React Hover to conditional render component
- render default src img if there is no image data fetched from database in react js
- how to keep displaying a border bottom for a link element when a user is active on a page
- configuring esbuild with react (replacing create-react-app)
- Reset Search State in Redux If User Leaves Page
- Passing state from child to parent component in react
- How can I share state between two custom hooks?