Giter Club home page Giter Club logo

Comments (4)

kidjp85 avatar kidjp85 commented on August 27, 2024 3

Hi @renatogalvones , I could see where is the problem here . But I still don't know why u guys need to use same key for both wrapper div and CardReview. What is the benefit of using the same key for <div key='item.id'><CardReview key='item.id'.... /></div> ? It will be very helpful, if u guys can put a reference link for this :)

I always use key only for root element in loop like

function CardSlider({ params, slides, Swiper, updateSliderDimensions }) {
  if (slides.length <= 0 || !Swiper) return false;

  const renderItem = item => {
    return (
      <div key={item.id}>
        <CardReview {...item} updateSliderDimensions={updateSliderDimensions} />
      </div>
    )
  }

  return (
    <Swiper {...params}>
      { slides.map(renderItem) }
    </Swiper>
  );
}

Thanks :)

from react-id-swiper.

sergiokopplin avatar sergiokopplin commented on August 27, 2024 2

@kidjp85 actually, we don't have to use. Your solution is better.

from react-id-swiper.

kidjp85 avatar kidjp85 commented on August 27, 2024

Hi @sergiokopplin , can u show me ur code for swiper. I wanna see how u render you children component :) . And thanks for your suggestion too. I will be great if u can make a PR for this :)

from react-id-swiper.

renatogalvones avatar renatogalvones commented on August 27, 2024

Hello @kidjp85 !

Thanks for making this awesome "proxy". Saved a lot of hard work here. =]

Here's how our code is implemented:

function CardSlider({ params, slides, Swiper, updateSliderDimensions }) {
  if (slides.length <= 0 || !Swiper) return false;

  slides.forEach((item) => {
    const cardReview = (
      <CardReview
        {...item}
        key={item.id}
        updateSliderDimensions={updateSliderDimensions}
      />
    );

    sliderItems.push(<div key={item.id}>{cardReview}</div>);
  });

  return (
    <Swiper {...params}>
      { sliderItems }
    </Swiper>
  );
}

This code is part of our "dumb" component which is responsible for only the rendering part.
We are requiring the Swiper on the componentWillMount on the "smart" component and passing it by props to the "dumb" one.

And as the React documentation suggests we are using the same id on the div and the CardReview.

from react-id-swiper.

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.