首页 > 解决方案 > 反应导航中的道具传播

问题描述

我在打字稿中构建了一个反应本机应用程序。我正在使用来自反应导航的抽屉项目组件。

<DrawerItems
  {...this.props}
  items={items}
  itemStyle={styles.drawerItem}
  labelStyle={material.body1}
  activeBackgroundColor="transparent"
/>

出于学习目的,我已经将我的 lint 设置得非常严格。现在我收到以下错误消息:

道具传播是禁止的(react/jsx-props-no-spreading)

我试图通过分开的道具,但它需要其他我不知道从哪里得到的道具。谁能告诉我如何在不传播道具的情况下重写它?

标签: typescriptreact-nativereact-navigation

解决方案


我想通了。我调试了道具并将所有孩子单独放入。完成的代码如下所示:

            <DrawerNavigatorItems
              items={items}
              itemStyle={styles.drawerItem}
              labelStyle={material.body1Object}
              activeBackgroundColor="transparent"
              drawerPosition="left"
              renderIcon={renderIcon}
              getLabel={getLabel}
              onItemPress={onItemPress}
            />

请注意,我同时也更新了我的包,所以 ...props 的原始子代可能会有所不同


推荐阅读