UNPKG

react-event-test

Version:

Event-driven alternative to React Context

9 lines (8 loc) 275 B
import { publish, subscribe } from './index.js'; const WS_URL = 'ws://localhost:8080'; subscribe(WS_URL, 'MY_EVENT', (data) => { console.log('MY_EVENT received:', data); }); setTimeout(() => { publish(WS_URL, 'MY_EVENT', { message: 'Hello from client!' }); }, 2000);