javascriptreactjsspectacle

how to control spectacle presentation with pure javascript?


I tried to get the count of all slides and change to one of them using plain javascript. I'm not into react and wasn't able to find a global object to call some functions on.

Is there something like: presentation.loadSlide(2); ?


Solution

  • Please add a reference to your Deck component like below

    <Deck ref={(deck) => {this.deck = deck; }} transition={["zoom", "slide"]} transitionDuration={500} theme={theme}>
      ...
    </Deck>
    

    Now you have a property by the name of deck in your component. Use componentDidMount lifecycle method to retrieve this.deck.props.children.length and assign it to window.slideCount.

    componentDidMount() {
      window.slideCount = this.deck.props.children.length
    }
    

    Now open browser console and type slideCount, you will se you have slide count displayed there. After that you can use following to change the slides

    window.location = "#/1"