lararara's avatar

Laravel Echo in React with Hooks and Providers

Using window in React is not really the React way, better to use Hooks instead. Except, Echo only needs to be instantiated once, thus use Providers and Hooks.

Since the provider is at the root, all components underneath just need to call useEcho() to get the initial Echo object and do everything you need to do. Similar to using window.Echo except more Reacty.

0 likes
0 replies

Please or to participate in this conversation.