0

i saw a code snippet which write this:

<OmniCarousel settings={sliderSettings}>
        {React.Children.map(children, (child, index) => <div key={`dashboardBanner_${index}`}>{child}</div>)}
      </OmniCarousel>

but i was wondering why it was not written as:

<OmniCarousel settings={sliderSettings}>
            {React.Children.map(children, (child, index) => React.cloneElement(child,<div key={`dashboardBanner_${index}`}>{child}</div>)}

The code compiles fine both ways. Is there someone to answer this?

1 Answer 1

1

They both are almost the same, with only difference in references. If you want to pass ref to child you can use React.cloneElement.

Docs: https://reactjs.org/docs/react-api.html#cloneelement

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.