You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+76-26Lines changed: 76 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,50 +26,92 @@ Earlier releases exposed a **class** component. The default export is now a **fu
26
26
| Area | Notes |
27
27
|------|--------|
28
28
|**React versions**| Supported as **peer** dependencies: **React 18** and **React 19** (with matching `react-dom`). |
29
-
|**Import**|Same as before: `import ReactPannellumfrom "react-pannellum"`. |
30
-
|**Static / imperative API**|Methods such as `ReactPannellum.getPitch()`, `loadScene`, `addHotSpot`, etc. remain on the **default export** object (same call pattern as the old class statics). |
31
-
|**Props**| Same props; **`prop-types` was removed** from this package — TypeScript users get exported types (`ReactPannellumProps`, etc.); plain JS apps do not get runtime prop validation from the library. |
32
-
|**Children**| Pass **`children` as normal JSX children** inside `<ReactPannellum>…</ReactPannellum>` (a root `<div>` wraps them). |
29
+
|**Import**|`import ReactPannellum, { usePannellum } from "react-pannellum"` (default export is the viewer component; **`usePannellum`** is the imperative API). |
30
+
|**Imperative API**|Use the **`usePannellum()`** hook from a component rendered **inside**`<ReactPannellum>...</ReactPannellum>`. It returns an object with all viewer methods (`getPitch`, `setYaw`, `loadScene`, …). **Static methods on the component and named exports such as `getConfig` are removed** — migrate to the hook. |
31
+
|**Props**| Same props; **`prop-types` was removed** from this package — TypeScript users get exported types (`ReactPannellumProps`, `PannellumViewerApi`, etc.); plain JS apps do not get runtime prop validation from the library. |
32
+
|**Children**|**Required for `usePannellum`:** render a child (or descendants) that calls the hook. Pass **`children` as normal JSX children** inside `<ReactPannellum>` (a root `<div>` wraps them). |
33
33
|**TypeScript**| Types ship with the package (`"types"` in `package.json`). |
34
34
|**Build output**| The library is compiled to **ESM** in `dist/` (no CommonJS bundle). |
35
35
36
36
Internals (hooks, cleanup, listener registration) changed; if you relied on undocumented behavior or private APIs, re-test after upgrading.
37
37
38
38
## Usage
39
39
40
-
1.[Config props](#config)
41
-
2.[API Events](#apiEvents)
42
-
3.[API Event Listeners](#apiEventListeners)
40
+
1.[`usePannellum` hook](#usePannellum)
41
+
2.[Config props](#config)
42
+
3.[Imperative API](#apiEvents)
43
+
4.[Event listener props](#apiEventListeners)
44
+
45
+
### <aid="usePannellum"></a> `usePannellum()`
46
+
47
+
Call **`usePannellum()`** from any **descendant** of `<ReactPannellum>` (for example a child component). It returns a stable object of imperative methods for **that** viewer instance (`PannellumViewerApi` in TypeScript).
@@ -391,11 +433,19 @@ Specifies an array containing RGB values [0, 1] that sets the background color f
391
433
392
434
If set to `true`, prevent displaying out-of-range areas of a partial panorama by constraining the yaw and the field-of-view. Even at the corners and edges of the canvas only areas actually belonging to the image (i.e., within [`minYaw`, `maxYaw`] and [`minPitch`, `maxPitch`]) are shown, thus setting the `backgroundColor` option is not needed if this option is set. Defaults to `false`.
393
435
394
-
## <aid="apiEvents" ></a> API Events
436
+
## <aid="apiEvents" ></a> Imperative API (`usePannellum`)
437
+
438
+
The Pannellum **instance** is created **after mount** (inside a `useEffect`). Methods on the object returned by **`usePannellum()`** read the **current** viewer ref when invoked, so you can call them from callbacks (e.g. button clicks) even before the panorama has finished loading — many calls simply no-op or return `undefined` until the native viewer exists.
395
439
396
-
The viewer is created **after mount** (inside a `useEffect` in the implementation). **Do not call** the static imperative methods above **in the same synchronous turn as the first render** — the internal viewer may not exist yet, so you can get `undefined` / no-ops.
440
+
Prefer **`onPanoramaLoaded`** when you need to run code exactly once after the panorama is ready.
441
+
442
+
In the reference below, assume:
443
+
444
+
```ts
445
+
const p =usePannellum();
446
+
```
397
447
398
-
Use **`onPanoramaLoaded`**, or a **`useEffect`** with an empty dependency array (runs after paint) so the component has mounted and the Pannellum instance exists.
448
+
Then use **`p.isLoaded()`**, **`p.getPitch()`**, etc. (same names as before, without the old `ReactPannellum.` prefix or top-level `getPitch` imports).
399
449
400
450
> ### isLoaded
401
451
>
@@ -568,7 +618,7 @@ Parameters:
568
618
569
619
> ### getCurrentScene
570
620
>
571
-
> Returns `object` with sceneId and current scene config.
621
+
> Returns the **current scene id** (`string`), same as Pannellum’s `getScene()`. For the full config object, use **`getConfig()`**.
0 commit comments