hoaiduyit/react-pannellum

Re-rendering the component won't trigger init

Closed this issue · 4 comments

Using the component more then once. i.e. render it in a modal, close the modal, then render the component again will break it.

This is caused by the variable outside the component

let myPannellum = undefined;
...

componentDidMount() {
    if (!myPannellum && this.props.imageSource) {
      // make sure that your pannellum has enough time to load
      setTimeout(() => {
        this.initPanalleum();
      }, 100);
    }
  }

Solution is to declare myPannellum-varible inside the component:

class ReactPannellum extends React.Component {
   myPannellum = null;
   ...
}

I will make a pull request.

A quick fix for this is to extend the component

import ReactPannellum from 'react-pannellum';

class Pannellum extends ReactPannellum {
    /**
     * Override ReactPannellum
     */
    componentDidMount () {
        if (this.props.imageSource) {
            this.initPanalleum();
        }
    }
}

Link to pull request => #5

@peterjohansson92 , everythings are good now, I merged your PR and update a new version. Thanks for your PR to help me solve my own problem. You always be welcome. Cheers

I'm sorry, but your PR has 1 problem, that this cannot use in static function. I must rebase it.

hi @peterjohansson92 , I changed the code again. If you still have that problem, please tell me or feel free just mail me. Thanks.