Shared counter
Same counter demo. The child opens with
noopener and runs on its own event loop — a busy parent never freezes the child, and vice versa.Count0
Child window
Open a paired popup. Click the second button to increment the child's counter remotely.
Code
The whole flow on the parent side. The child mirrors it.
parent.tsx
import { useIwpcWindow } from '@silurus/iwpc';
const iwpc = useIwpcWindow({
transport: 'broadcastChannel',
// channelName: 'myapp:iwpc', // pin per app to avoid origin-wide collisions
});
useEffect(() => {
iwpc?.register('INCREMENT_COUNTER', () => setCount((c) => c + 1));
return () => iwpc?.unregister('INCREMENT_COUNTER');
}, [iwpc]);
// noopener by default — no Window reference between the two sides.
const child = await iwpc?.open('./child', { width: 520, height: 540 });
child?.invoke('INCREMENT_COUNTER');