Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 days ago.
Improve this question
I am trying to retrieve the most recent message in a chat room and I am using React Native. I have stored all the chat messages in the chat state, however, my current code only returns the second to last message. Can anyone assist me in retrieving the latest message in the room?
const GetLastMessage = chat.length > 0 ? chat[chat.length - 1] : "New Message";
I think the reason for this is its retrieving second last msg is your component state is not updated yet and you are already getting that msg.Make sure a point where you are getting updated state and then retrieve a last msg.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I have this saved in the database, but I can't find the correct line to console log it.
This is the last thing I tried and still not working:
var linesRef = database.ref("/lines");
console.log(
linesRef
.child("L1")
.val().eventattr
);
There are two ways to fetch data from firebase realtime database.
Either you can set a listener, which will automatically sync the data whenever there is a change in the database or you can do one time fetch
in your particular case (to fetch it one time)
you can do
const linesRef = firebase.database().ref("/lines");
linesRef.once("value")
.then(response => console.log(response.val()));
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
This is what my database looks like:
My question is how to I decrement the value of FIELD11 i.e. "4" in my realtime database in Firebase using javascript, everytime I click on DECREMENT Button on my html page it should decrement this value and get updated in realtime database. Thank You
I recommend you use a Firebase transaction.
When working with data that could be corrupted by concurrent modifications, such as incremental counters, you can use a transaction operation.
Example:
https://firebase.google.com/docs/database/web/read-and-write#save_data_as_transactions
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I'm fetching multiple post from DB. There is a option for make post as Favourite, I'm using toastr for showing notification. every post has a id="favourite_ads". but toastr notification only works for the 1st post. But i want to show notification for all of the posts. I have uploaded snapshot.
Please help.
You need to change the id attribute by common classes since the identifier should ne unique in the same document.
If you've duplicated identifiers always the first one will be considered that why the toastr works just for the first post.
<a class="btn btn-defaul.... favorite_ads" ><span>add as Favourite </span></a>
$('.favourite_ads').click(function(){
...
});
Use class instead then your code should be like the above example.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Below is sample example for counter but i have to maintain the state after page is refree.For example i will increment the counter to 10 and next time when my page refreshes the page should start with 10 instead of 1.
Can anyhow guide me regarding this.
If you want to use cookies JS-cookie is really handy. Setting and retrieving cookie is really easy.
Use localStorage for that.
In your action handler do:
let counter = window.localStorage.getItem("counter");
window.localStorage.setItem("counter ", ++counter);
Then in your componentDidMount do:
let counter = window.localStorage.getItem("counter");
this.setState("counter", counter);
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
i am using google maps api in java script. i want to find the duration between two locations. but i got error as route undefined. here i am define as
farevalue =gm.directions.route(booking_count.booking_from,booking_count.destination_to,function(err,result){
console.log(data.socket_session_id);
durtion = result.routes[0].legs[0].duration.text;
km = result.routes[0].legs[0].distance.text;
distance =result.routes[0].legs[0].distance.value;
}
Sorry i found the answer for my question. I didn't give the array index for my array. so it takes undefined value for addresses.
The routes simplified syntax is routes(starting point address, ending point address , callback function). In callback function we can find the distance and duration. Make sure that the addresses are correctly initialized.