我想知道属性如何'在此React代码(提供此道具的方式)中起作用)
父组件!
<CarouselSlick
items={suffled || children}
{…customFields}
isSwipe={false}
hideControlsMobile={false}
/>
子部分!
const CarouselSlick = (props) => {
const {
items = [],
hideControlsMobile,
isAutoPlay = false,
isSwipe = true,
} = props;
为什么有一个空数组? 据我所知,
const { items } = props;
上述代码是我所知道的。 为什么“ ISSWIPE”变得“ true”?它的原始值是从父组件中的错误。 我一直在看这个代码数字,
const { items, hideControlsMobile, isAutoPlay, isSwipe } = props;
我可能知道那是如何运作的吗?
Parent Component!
<CarouselSlick
items={suffled || children}
{…customFields}
isSwipe={false}
hideControlsMobile={false}
/>
Child Component!
const CarouselSlick = (props) => {
const {
items = [],
hideControlsMobile,
isAutoPlay = false,
isSwipe = true,
} = props;
why is there an empty array?
As far as I know,
const { items } = props;
Above code is what I've known.
And why 'isSwipe' is getting 'true'? Its original value is false from Parent Component.
I have been watching only this code figure
const { items, hideControlsMobile, isAutoPlay, isSwipe } = props;
May I know how that is operating?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ISSWIPE必须是错误的,这就是JavaScript中默认值概念到可变初始化,如果未定义,则默认值,
eCmascript 2015允许默认参数值作为默认值,
在您的情况下,名称不匹配,
可能的修复,
isSwipe must be false, that is default values concept in javascript to variable initialization with default values if undefined,
ECMAScript 2015 allows default parameter values as default values,
in you case, name mismatch,
possible fix,
这些是默认值。 React中的组件就像JS功能一样。如果
carouselslick
component在没有isswipe
参数的情况下被调用,则将设置为组件内的false
。物品也是如此。示例父部分:
子组件:
Those are default values. Components in React are just like JS functions. If
CarouselSlick
component was called withoutisSwipe
parameter it would be set tofalse
inside the component. The same happens with items.Example parent component :
Child component: