How do I handle a separate state of each browser tab in ReactJS?

We open a new window tab, which contains a userList based on the selected userId in the list. I open a new window like this:

< pre>this.props.getVisitDetails(this.props.userId)
var win = window.open(‘./requisition’,’_blank’);
win.onload = function() {this. document.title = windowTittle; }
win.focus();
this.state.oldWindow.push(win);

Here, I get the userId from the Redux store. Question Yes, if I open multiple window tabs, the userId on each window tab will have the same userId, and when you click refresh, all window tabs will have the same data. So my question is how to Does each window tab maintain a separate state?

Note: All browser tabs share the same storage state that we saved using the createstore method, so in my case, visitid will update on each line click, which will open the browser’s new Tab. This is how data is “shared”

Your store will not be in multiple tabs Shared between pages, so every time you open a new tab, your entire application will be loaded again and the fresh store will be initialized at the same time. Therefore, in your case, the simple solution is to open the URL that contains the userId as a query parameter New tab (window.open(‘./ requisition? userId = ${userId}’,’_ blank’);). This way you can maintain a separate userId in different browser tabs.

We open a new window tab, which contains a userList based on the selected userId in the list. I open a new window like this:

this. props.getVisitDetails(this.props.userId)
var win = window.open('./requisition','_blank');
win.onload = function() {this.document.title = windowTittle; }
win.focus();
this.state.oldWindow.push(win);

Here, I get the userId from the Redux store. The problem is if I Open multiple window tabs, then the userId on each window tab will have the same userId, when you click Refresh, all window tabs will have the same data. So my question is how to choose for each window Does the card maintain a separate state?

Note: All browser tabs share the same storage state that we saved using the createstore method, so in my case, visitid will update on each line click, which will open the browser’s new Tab. This is how data is “shared”

Your store will not be shared between multiple tabs, so every time you open a new tab , Your entire application will be loaded again and the fresh store will be initialized at the same time. So, in your case, the simple solution is to open a new tab (window.open(‘./requisition ?UserId = ${userId}’,’_ blank’);). This way you can maintain a separate userId in different browser tabs.

Leave a Comment

Your email address will not be published.