$ show cloudflare/stream-react
This repository is a React component library for embedding Cloudflare Stream video players. It provides a `<Stream>` component that handles loading the Cloudflare Stream SDK, creates an iframe for the player, and synchronizes React props with the player's imperative API. The architecture centers around custom React hooks for script loading (`useStreamSDK`), property synchronization (`useProperty`), and event management (`useEvent`). The component is designed to be used in React applications, with props controlling video playback, appearance, and event handling. External dependencies include React (peer dependency) and the dynamically loaded Cloudflare Stream SDK.
The LLM identified 2 files worth highlighting for reuse:
A custom React hook that safely loads an external script (the Cloudflare Stream SDK) and exposes its availability. It prevents duplicate script loading, handles script load events, and is safe for server-side rendering by checking the window object. This pattern is reusable for any third-party SDK loaded via a script tag.
Contains two custom React hooks: `useProperty` for synchronizing a prop value to a DOM element property (with automatic cleanup), and `useEvent` for attaching and cleaning up event listeners on a DOM element. These hooks encapsulate common patterns for interacting with imperative APIs from React, reducing boilerplate and preventing memory leaks. Though not exported, they demonstrate reusable patterns that could be extracted.