Giter VIP home page Giter VIP logo

Comments (10)

MacKentoch avatar MacKentoch commented on August 27, 2024 15

@abhilashsajeev @benbayard In ES6 Carousel.ControllerMixin seems no more useful.
There even easier way to control your carousel (it was my need)

Just use ref to get access to backing instance of Carousel:

class myComponent extends Component {

// in render :
      <Carousel
          ref="carousel"
          decorators={CarouselDecorator}>
        ....


       // you control your Carousel without mixin
       <button
           className="btn btn-primary"
           onClick={(e)=>this.handlesNext(e)}>
            next
        </button>

// your onclick
  handlesNext(event) {
    event.preventDefault();
    // ref="carousel" so :
    this.refs.carousel.nextSlide();
  }

It works great with less code.

from nuka-carousel.

abhilashsajeev avatar abhilashsajeev commented on August 27, 2024 2

Well the Carousel.ControllerMixin was one of the important part when I am trying to call some this like this.state.carousels.carousel

anyway I have found a way to use it in ES6

class CarouselCmp extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      carousels : {}
    }
    this.setCarouselData = Carousel.ControllerMixin.setCarouselData;
  }
}

from nuka-carousel.

benbayard avatar benbayard commented on August 27, 2024

Hey @abhilashsajeev I believe that Mixins are not support with es6 classes. If you would like to use Mixins with this component you have to use React.createClass which has the same ES5 syntax.

from nuka-carousel.

kenwheeler avatar kenwheeler commented on August 27, 2024

^ true story

from nuka-carousel.

alduro avatar alduro commented on August 27, 2024

anyone tried it out using react-css-modules ?

from nuka-carousel.

alduro avatar alduro commented on August 27, 2024

Confirmed. it works perfect with react-css-modules.

from nuka-carousel.

JulianJorgensen avatar JulianJorgensen commented on August 27, 2024

@MacKentoch Thanks for the tip! Can you please show me your full code? Would particularly like to see your CarouselDecorator variable.

By doing it this way will the controls be within the actual Carousel div, or outside? I am asking mainly because of styling purposes (placing the controls relative to their parent container).

Thanks mate

from nuka-carousel.

ragefuljoe avatar ragefuljoe commented on August 27, 2024

@MacKentoch
Is it possible to get current slide info using this refs way?

from nuka-carousel.

MacKentoch avatar MacKentoch commented on August 27, 2024

@JulianJorgensen sorry it makes a while I don't use this library. I just used it for an office project.

@ragefuljoe you can access anything from ref.
As an example accessing all state is:

this.refs.carousel.state

So you can access slideIndex:

this.refs.carousel.state.slideIndex

from nuka-carousel.

ragefuljoe avatar ragefuljoe commented on August 27, 2024

<Carousel ref={(c) => this.slider = c }> {carouselItems} </Carousel>

Doing the above, not able to access this.slider.state.slideIndex. Is usage different now with es6/dep of string refs?

from nuka-carousel.

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.