Giter Site home page Giter Site logo

Comments (4)

Snorvarg avatar Snorvarg commented on July 20, 2024

Hi,
I am looking at the same thing. The this.state.current keep track of the current item active, but I have not found a way to get it out from the component. (react beginner) :)

It would be nice to have some sort of callback for this?

from react-coverflow.

asalem1 avatar asalem1 commented on July 20, 2024

Hey there, an example of this exists on the following site in the randomize button section:

http://andyyou.github.io/react-coverflow/

from react-coverflow.

Snorvarg avatar Snorvarg commented on July 20, 2024

Asalem1, the example you provide show how to set current item, but not how to get it. It would be great with a similar code example showing how to get the currently selected image, or better some kind of callback called whenever coverflow change which image is currently shown.

from react-coverflow.

Snorvarg avatar Snorvarg commented on July 20, 2024

I tried extending the Coverflow class, though run into some problems. Maybe this is not the way to go?

class CoverflowExt extends Coverflow {
  _handlePrevFigure = (e) => {
    super._handlePrevFigure(e);

    console.log('_handlePrevFigure() called. Callbacks called here.');
  }

  _handleNextFigure = (e) => {
    super._handleNextFigure(e);

    console.log('_handleNextFigure() called. Callbacks called here.');
  }
}

In an ideal world, I would have a place to call a callback when any mouse wheeling or dragging has happened. But I get the error message "Uncaught TypeError: Cannot read property 'call' of undefined" trying to call super._handleNextFigure(e);


I got it working this way:

Overriding as in the example above I am able to override the setState and get a place where I can call callbacks:

  setState(props) {
    let prev = this.state.current;

    // Source: https://stackoverflow.com/questions/41896878/react-setstate-getstate-and-asynchronous
    super.setState(props, () => {
      console.info(this.state.current);
      console.log('this works');

      if (prev !== this.state.current) {
        console.log('callbacks n stuff here');
      }
    });
  }

Hope it helps someone!

from react-coverflow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.