Updating React Component state Dynamically based on server state

I have a component that shows no of players logged in as soon as the component loads.

function PlayerList({gamePin}){
const [playerList, setPlayerList] = useState("");
useEffect( ()=>{
         .then( response =>{
    <div className='container'>
        <div className='lobbycontainer'>
            <Grid container spacing={3}>
                    <Player {PlayerName,PlayerId} />

export default PlayerList;

This will display the name of the player who is logged in and any other players already logged into the lobby.

But my question is how do the players who are already logged in will get to know about the new players who joined.

Possible Approach

  1. Send a request with a time interval of every 2 seconds.


Is this the right way to do this? are there any alternate approaches?

How does a component dynamically update its state based on the changes in the backend? and respond to the changes by rerendering the component to reflect the changes.

98 thoughts on “Updating React Component state Dynamically based on server state”

Leave a Comment