useState in React Native fails to mount new value?
Trying to retrieve a list of numbers for which will be used later on to retrieve more data.
const [listData, setList] = React.useState();
let tempSim = Temp();
const setLog = async() => {
const array = [];
const date = getDate();
const dbCon = database.ref('Conditions/Log/Temp/' + date);
await dbCon.get().then((snapshot => {
snapshot.forEach(data => {
array.push(data)
})
}))
dbCon.off()
console.log(array)
setList(array)
console.log(listData)
}
The array prints fine with all the correct data, however as soon as I set the state and try print that the only output I've been able to get is undefined?
do you know?
how many words do you know
See also questions close to this topic
-
how to change prettier format for react native
my code formatting prettier didn't works well for react native, i don't understand where to config it but it works well with flutter
from this code
import { View, Text } from 'react-native' import React from 'react' export default function App() { return ( <View> <Text>Apps</Text> </View> ) }
it's formatted to this
import { View, Text } from 'react-native' import React from 'react' export default function App() { return ( < View > < Text > Apps < /Text> < /View> ) }
-
MarkLogic server-side JavaScript and XQuery
I am just starting using NoSQL MarkLogic DB and trying to choose for me the best query language to learn and use in future. On server side MarkLogic provides the possibility to use JavaScript API or XQuery API.
I want to receive an advice. Which language is better to concentrate on and learn? JavaScript or XQuery?
- Popover in chrome extension using js
-
How can I fixed my problem"FirebaseError: Firebase: Error (auth/invalid-api-key)."
My environment variable is ok. No comas and name mistakes but they given me error like "FirebaseError: Firebase: Error (auth/invalid-api-key)". How can I fixed it. Please Help me...
This my .env file
REACT_APP_apiKey=AIzaSyBWobnhbdeMdNpXXXXXXXXXXXXXXXXXXXX REACT_APP_authDomain=XXXXX.firebaseapp.com REACT_APP_projectId=XXXX REACT_APP_storageBucket=XXXXX.appspot.com REACT_APP_messagingSenderId=4997390XXXXX REACT_APP_appId=1:4997390XXXXX:web:cc7bc80aa1bdb78fXXXXXX REACT_APP_measurementId=G-M1XDXXXXXX
This my firebase config file
const firebaseConfig = { apiKey: process.env.REACT_APP_apiKey, authDomain: process.env.REACT_APP_authDomain, projectId: process.env.REACT_APP_projectId, storageBucket: process.env.REACT_APP_storageBucket, messagingSenderId: process.env.REACT_APP_messagingSenderId, appId: process.env.REACT_APP_appId, measurementId: process.env.REACT_APP_measurementId, }; when I debugging firebaseConfig object console.log(firebaseConfig.apiKey); ==========> undefined console.log(firebaseConfig.authDomain); ==========> undefined console.log(firebaseConfig.projectId); ==========> undefined console.log(firebaseConfig.storageBucket); ==========> undefined console.log(firebaseConfig.measurementId); ==========> undefined console.log(firebaseConfig.appId); ==========> undefined console.log(firebaseConfig.measurementId); ==========> undefined
client side given error this "FirebaseError: Firebase: Error (auth/invalid-api-key)"
-
How to order comments in firebase firestore by createdAt
I have a document in which there is a comments array of objects and each object has createdAt property. I want to sort all the comments that are inside the comments array using the createdAt property, so, a new comment comes to the top.
I did some research and found that we can do this in firebase's real-time database but I want to do the ordering of data using firestore.
Here is my code:
import { useEffect, useRef, useState } from "react" // firebase import import { doc, onSnapshot, orderBy, query } from "firebase/firestore" import { db } from "../firebase/config" export const useDocument = (c, id, o) => { const [document, setDocument] = useState(null) const [error, setError] = useState(null) // realtime document data useEffect(() => { let docRef = doc(db, c, id) if (o) { docRef = query(docRef, orderBy("createdAt", "desc")) // this is not working } const unsubscribe = onSnapshot( docRef, (snapshot) => { // need to make sure the doc exists & has data if (snapshot.data()) { setDocument({ ...snapshot.data(), id: snapshot.id }) setError(null) } else { setError("No such document exists") } }, (err) => { console.log(err.message) setError("failed to get document") } ) // unsubscribe on unmount return () => unsubscribe() }, [c, id]) return { document, error } }
-
How to group firebase data in flutter with DateTime?
I am making a chat application in flutter using firebase. I want to show a header with the date whenever the date changes. How can I group messages in flutter coming from firebase on the basis of date and show a header with the changed date?
I have tried GroupedListView package but I was not able to retrieve the chatmessages successfully.
-
Command failed: xcrun instruments -s
I want to run my react native app on a real ios device with this line :
npx react-native run-ios --udid SOME-UDID
but i got this error :
xcrun: error: sh -c '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -find instruments 2> /dev/null' failed with exit code 17664: (null) (errno=No such file or directory) xcrun: error: unable to find utility "instruments", not a developer tool or in PATH error Command failed: xcrun instruments -s xcrun: error: sh -c '/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -find instruments 2> /dev/null' failed with exit code 17664: (null) (errno=No such file or directory) xcrun: error: unable to find utility "instruments", not a developer tool or in PATH
everything is ok on simulator
I'm using XCODE 13
-
How to maintain global states created dynamically
I am trying to Display list of items with then name and button to download its respective file Same list are available in different other screens. When I click on download
State info sharing: It should start download and the state/progress of the download should be visible to same item available in different other screens.unique identifier is item id
There can be parallel downloads
Problem statement:
- Unable to share the information for same item if we use state within the same item
- On use of redux its solving problem 1 however Parallel download information is getting overwritten as its writing to same reducer state
Any idea or approach is appreciated. Thanks