简体   繁体   English

新的React模块位于另一个反应组件中

[英]New React module inside another react component

So if it's silly question, please excuse me. 所以,如果这是一个愚蠢的问题,请原谅。

I'm using React Carousel Component (react-slick) for my project. 我正在为我的项目使用React Carousel Component(react-slick)。 What i want to achieve, inside this block i want to use my module " CarouselSlide ". 我想要实现的目标,在这个块中我想使用我的模块“ CarouselSlide ”。

<Slider {...settings}> //--> react-slick component tag
  <CarouselSlide/>     //--> my module
</Slider>

CarouselSlide is my react module shows single carousel slide. CarouselSlide是我的反应模块显示单个旋转木马幻灯片。

Is it possible to use this way or do i have to edit " react-slick " component own source code ? 是否可以使用这种方式或者我必须编辑“ react-slick ”组件自己的源代码?

Depending on how you want to display the slides, the base react-slick my prove difficult since that component seems to display each sibling element in its own slide. 根据你想要显示幻灯片的方式,我认为基础react-slick很难,因为该组件似乎在其自己的幻灯片中显示每个兄弟元素。 The problem with using your own React component as a child for react-slick is that your component must return a single parent and there currently is no way of sending multiple sibling elements in your render function's return statement. 将您自己的React组件用作反应的子react-slick是您的组件必须返回单个父进程,并且当前无法在render函数的return语句中发送多个兄弟元素。

react-slick seems to want a setup like the following: react-slick似乎想要一个如下设置:

<Slider {...settings}>
    <div>1</div>
    <div>2</div>
</Slider>

Yet creating a component in React and returning 然而在React中创建一个组件并返回

<div>1</div>
<div>2</div>

Would return an error since you need a single parent encapsulating the return statement. 由于您需要封装return语句的单个父级,因此会返回错误。

Now instead if you had a more complicated component to define EACH slide you can then do something like: 现在,如果您有一个更复杂的组件来定义EACH幻灯片,那么您可以执行以下操作:

<Slider {...settings}>
    <MyComponent />
    <MyComponent />
</Slider>

So it really boils down to how you use it. 所以它真的归结为你如何使用它。 If you want to return the ENTIRE set of slides in a single component, you'll need to edit the base react-slick component to allow that. 如果要在单个组件中返回整个幻灯片组,则需要编辑基本react-slick组件以允许该组件。

Take a look at this jsFiddle and you can see the problem. 看看这个jsFiddle你可以看到问题。

是的可能。你可以在组件内部组件。这就是反应如何工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM