Skip to main content
WidgetProvider.jsx

Installation

Usage

Wrap a single element in WidgetProvider and read the mode with WidgetConsumer (a render prop) or the useWidgetContext hook.
WidgetProvider tracks whether its child is on screen (via react-intersection-observer). It exposes:
  • mode: "inline" while the child is in view, the player is stopped, or the widget was closed. Otherwise "widget" (e.g. a floating mini-player once the user scrolls past it).
  • close(): pins mode back to "inline" permanently.
WidgetProvider clones its single child to attach the visibility ref, so it must wrap exactly one element. Read the value lower in the tree with useWidgetContext(), which throws if used outside a WidgetProvider.

Reference