Coder Social home page Coder Social logo

Current Item about react-elastic-carousel HOT 3 CLOSED

sag1v avatar sag1v commented on May 18, 2024
Current Item

from react-elastic-carousel.

Comments (3)

sag1v avatar sag1v commented on May 18, 2024 2

You can do it by tracking the current active item yourself via the the change handlers, for example onNextEnd and onPrevEnd.
See the docs for more details.

here is a running example

Here is a sample gist:

const items = [1, 2, 3, 4, 5, 6, 7, 8];

function App() {
  const [currentItem, setCurrentItem] = React.useState(0);
  const onCurrentChange = current => {
    setCurrentItem(current.index)
  }

  return (
    <div className="App">
      <Carousel
        onNextEnd={onCurrentChange}
        onPrevEnd={onCurrentChange}
      >
        {items.map((item, i) => {
          const className = currentItem === i ? "active" : "";
          return (
            <Item key={item} className={className}>
              {item}
            </Item>
          );
        })}
      </Carousel>
    </div>
  );
}

I'm going to close this as its not a bug or a feature request, and i think you got an answer to your question.
If you think you didn't get a proper solution then feel free to re-open this issue. 🙂

from react-elastic-carousel.

WassimHakim avatar WassimHakim commented on May 18, 2024

It worked thanks. One more question, how do we configure an infinite loop on it?

from react-elastic-carousel.

sag1v avatar sag1v commented on May 18, 2024

Infinite loop is not supported yet see #9 , i didn't have much time to work on it. PR is welcome.

from react-elastic-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.