Reputation: 311
For simplicity assume that I have entity user and in my frontend side (react) I am making an Axios get request to get all users to display them.
In the componentDidMount
I am doing a get request const res = axios.get(myurl)
then map the res
to be displayed.
However, if a new user is entered in the database I have to refresh the page to see the update.
Here is my question, how to make the get request to be like running or something like this so if any changes happens in the database it reflects the get request.
Upvotes: 5
Views: 3929
Reputation: 311
Before reading the answer, you need to know that this case is about the real-time updates concept and not a problem with a line of code solution. You need to implement real-time system in your app to achieve what you want.
Upvotes: 1
Reputation: 11
You can use the useEffect in react
import React,{useEffect}from 'react'
function getAllUsers(){
//your code here...
}
useEffect(()=>{
getAllUsers();
})
Upvotes: 1