REACT Plotly - TypeError: createPlotlyComponent is not a function

335 views Asked by At

When moving to the latest plotly their example no longer works

The plotly-react readme points to this codepen (in the Loading from a tag section) : https://codepen.io/rsreusser/pen/qPgwwJ?editors=1010

Increasing the version of react-plotly.js from "1.0.2" gives error "latest" TypeError: createPlotlyComponent is not a function. (In 'createPlotlyComponent(Plotly)', 'createPlotlyComponent' is an instance of Object)

Would love to know how to solve this... (tried many things - I'm not a js expert)

html: <script crossorigin src="https://unpkg.com/react-plotly.js@latest/dist/create-plotly-component.js"></script>

js: const Plot = createPlotlyComponent(Plotly);

1

There are 1 answers

0
Lucas P. Luiz On BEST ANSWER

In https://unpkg.com/react-plotly.js@latest/dist/create-plotly-component.js you can see a line exports["default"] = plotComponentFactory;

I guess the factory isn't set up properly.

const Plot = createPlotlyComponent.default(Plotly) works.

You could also do:

createPlotlyComponent = createPlotlyComponent.default
const Plot = createPlotlyComponent(Plotly)