react-plotly.js is the official React component wrapper for the plotly.js graphing library, currently at stable version 2.6.0. It provides a declarative way to render interactive charts within React applications. The library maintains an active release cadence, with minor updates addressing bug fixes and new plotly.js event support occurring every few months. A key differentiator is its design as a 'dumb' React component, meaning it does not internally manage plot interactions (like zooming or panning) as part of its state. Developers must explicitly capture and manage these changes using callback props like `onUpdate` or `onInitialized` to persist user interactions across re-renders. It requires `react` and `plotly.js` as peer dependencies, allowing users to control the plotly.js bundle size and version and integrate custom bundles. This component forms the basis of Plotly's React component suite.
npm install react-plotly.jsVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to render a basic scatter and bar chart using the Plot component with static data and layout, enabling the mode bar.
Update your React components to use modern lifecycle methods or hooks as recommended by React's documentation.
Use the `onInitialized` and `onUpdate` callback props to capture the plot's `figure` state (data, layout, frames, config) and store it in your parent component's state or a global store.
Ensure `data`, `layout`, or `config` props change identity (shallow `===`) or explicitly update the `revision` prop or `layout.datarevision` to force a re-render. Consider using immutability helpers for complex state updates.
Always pass copies of your `layout` and `data` objects as props to `Plot` if you need to ensure their original references are not modified by the component. For example, use spread syntax (`{...myLayout}`) or deep cloning if necessary.Pass new object references for `data`, `layout`, or `config` props when they change, or increment the `revision` prop or `layout.datarevision` to force an update. Capture interactive changes via `onUpdate`.
Use `import Plot from 'react-plotly.js';` for ES Modules. If using CommonJS, use `const Plot = require('react-plotly.js').default;`.