K
K
Kafkae2019-03-28 16:21:55
React
Kafkae, 2019-03-28 16:21:55

How to forward one component to another?

There is a slider with pictures, and I want to forward not img (which cannot be done by default), but for example already a card with goods and, for example, other props. But I do not understand how it is how to forward through props. How can it be easier to solve. https://codesandbox.io/s/ly8vp183p9

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2019-03-28
@Kafkae

const ItemComponent = props => (
  <div>
    <p>{props.title}</p>
  </div>
);

...

<Carousel
  items={items}
  ItemComponent={ItemComponent}
/>

UPD. https://codesandbox.io/s/42p1q66589

A
Andrey Okhotnikov, 2019-03-28
@tsepen

You can drop a component like this

<Carousel>
        <div>
          <p>text</p>
        </div>
</Carousel>

In the Carousel component, it will be available via props.children

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question