How to add item to array with useState hook in React? [duplicate] - javascript

This question already has answers here:
How to return many Promises and wait for them all before doing other stuff
(6 answers)
Push method in React Hooks (useState)?
(8 answers)
Correct way to push into state array
(15 answers)
Closed last year.
I am new to React and I searched examples for this questions but I could not achieve to do this.
I make 2 separate calls to backend and getting 2 different dto and I want to put them into one table data instead of 2 separate ones.
Here is my code:
const [lensTableData, setLensTableData] = useState<InternalDTO>();
const [dbsaTableData, setDbsaTableData] = useState<InternalDTO>();
useEffect(() => {
context.services.adapterStatus.getLensAdapterStatus()
.then((resp) => setLensTableData(resp));
context.services.adapterStatus.getDbsaAdapterStatus()
.then((resp) => setDbsaTableData(resp));
}, [])
It is working but what I want to do is to make just 1 array instead of 2 different and I want to add 2nd one into array after the first one. How can I combine them ?

Related

How to update a field of a nested object in Firestore array field with React? [duplicate]

This question already has answers here:
Firestore Update single item in an array field
(2 answers)
How to update() an array of maps-objects on Firestore in Angular or Angularfirestore?
(1 answer)
How can I update an object inside of an array in firestore?
(1 answer)
Closed last month.
I have the following collection:
collection firebase
And within this collection (0) I have nested modules -> videos as shown below:
enter image description here
What I want to achieve is that in the section, for example: modules[0].videos[0], the property finishedState = true. I am trying as follows:
try {
const cursos = doc(firebase.db, "misCursos", "7eIHn6FtYIOcFEWq2mXE");
await updateDoc(cursos, {
"0.modulos.0.videos.0.videoFinalizado": true,
});
} catch (error) {
console.log(error);
}
But this removes all other modules with their videos and leaves me only **modules[0] -> videos[0] -> **finishState: true
My question is, how can I do to modify ONLY the property that belongs to that section?

How to delete a element from a nested array in firestore [duplicate]

This question already has answers here:
Firestore Update single item in an array field
(2 answers)
how can i update a specific object property within an array in firebase [duplicate]
(2 answers)
Closed 4 months ago.
I want to delete the 0 element of questions array. I've tried this
const documentRef = db.collection(collection).doc(challengeId)
await documentRef.update({
[`stages.0.surveys.0.questions.0`]: firebase.firestore.FieldValue.delete()
})
But it doesn't work. I would appreciate any help. thank you

Firestore update nested data [duplicate]

This question already has answers here:
How can I update an object inside of an array in firestore?
(1 answer)
How to update an "array of objects" with Firestore?
(18 answers)
Is there any way to update a specific index from the array in Firestore
(3 answers)
Closed 8 months ago.
i am stuck with a problem with firebase (with Vue). I want to add the user id to a specific map (yes, maybe or no) when the user presses a specific button. But Im having trouble add/update the data because its nested.
Here is my data structure in Firestore
I want to add the user id in a map, something like this:
dates: {
[
0: {
yes: [userId1, userId2]
}
]
}
Does anyone can help me pushing the user ids into the arrays?
Unfortunately, right now it is not possible to update a specific element of the array. You can add new items or remove them - look here. But I would consider a little change in the approach and create a collection called dates in which you can define documents, which will contain yes, no, maybe arrays, which can be easily updated - in the way mentioned before.

Add multiple conditions to Firestore's get() with loop, general javascript issue [duplicate]

This question already has answers here:
Firestore: Multiple conditional where clauses
(10 answers)
Closed 3 years ago.
Is there a way how to dynamically add multiple conditions to Firestore's get request?
I saw a few solutions there but they included multiple get() requests inside for/while loops. I would need to find a solution that adds multiple filters based on data in array(s).
Issue is that I have several filters with multiple choice values and I am not sure how many of them will user select.
citiesDb
.where('city', '==', 'New York')
.where('city', '==', 'Paris')
.where('city', '==', 'London')
// It can be multiple more based on let cities = [] (with size of 0 to many)
// There can be also a few more arrays with filters
.get()
Does it work for you?
let query = citiesDb;
for (const city of cities) {
query = query.where("city", "==", city);
}
query.get().then(...) // result

React Redux Array Filter [duplicate]

This question already has an answer here:
React Redux Cant add item into list in the state
(1 answer)
Closed 4 years ago.
Could some one tell how this image data iterate using array map and assign into the UL LI tag
Assume this is the response generated from and I want to populate this data somewhere.
Specify key to access payload.
return { ...state, filterArr : filterArr }

Categories

Resources