Shared apps
Shared App Isolated State
Keep state local to a single port when using Reactant Share.
Shared modules synchronize state between the server and clients. If a module
stores per-tab UI state, inject PortDetector and call disableShare(this)
when the module is constructed.
import { action, injectable, state } from 'reactant';
import { PortDetector } from 'reactant-share';
@injectable()
class LocalPanel {
constructor(port: PortDetector) {
port.disableShare(this);
}
@state expanded = false;
@action
toggle() {
this.expanded = !this.expanded;
}
}Call the local module's action directly from its view. Use separate modules for state that should synchronize, such as the count in the cross-tab example.
Examples
The isolated-state tests show shared and per-tab state updating in the same app.