React 渲染毫无意义 div 破坏了我的 flexbox 风格

React renders pointless div breaking my flexbox style

我熟悉 React Native,但不太熟悉 ReactJS。我有一个样式问题:我正在为一个业余项目修改这个库:https://github.com/rcdexta/react-trello 我感兴趣的代码如下所示:

// Render Method
return (
    <BoardDiv style={style} {...otherProps} draggable={false}>
      <UpdateModal
        isOpen={this.state.isOpen}
        onClick={this.closeModal.bind(this)}
        card={this.state.card}
        onRequestClose={this.closeModal}/>
      <PopoverWrapper>
        <Container
          orientation="horizontal"
          onDragStart={this.onDragStart}
          dragClass={laneDragClass}
          dropClass=""
          onDrop={this.onLaneDrop}
          lockAxis="x"
          getChildPayload={index => this.getLaneDetails(index)}
          groupName={this.groupName}>
          {reducerData.lanes.map((lane, index) => {
            const {id, droppable, ...otherProps} = lane
            const laneToRender = (
              <Lane
                key={id}
                boardId={this.groupName}
                id={id}
                getCardDetails={this.getCardDetails}
                onCardClick={(cardId, metadata, laneId) => {
                  const allCards = [].concat(...this.props.reducerData.lanes.map((lane) => lane.cards))
                  const cardData = allCards.filter((e) => e.id === cardId)[0]
                  this.modifyCardTitle(cardData)
                }}
                index={index}
                droppable={droppable === undefined ? true : droppable}
                {...otherProps}
                {...passthroughProps}
              />
            )
            return draggable && laneDraggable ? <Draggable key={lane.id}>{laneToRender}</Draggable> :
              <span key={lane.id}>{laneToRender}</span>
          })}
        </Container>
      </PopoverWrapper>
      {canAddLanes && (
        <Container orientation="horizontal">
          {editable && !addLaneMode ? (
            <LaneSection style={{width: 200}}>
              <NewLaneButton onClick={this.showEditableLane}>{addLaneTitle}</NewLaneButton>
            </LaneSection>
          ) : (
            addLaneMode && this.renderNewLane()
          )}
        </Container>
      )}
    </BoardDiv>
)

然而渲染看起来像这样:

<div class="react-trello-board sc-bdVaJa eBPLjG" data="[object Object]" draggable="false">
  <div> <!--The problem-->
    <div class="smooth-dnd-container horizontal">
        <section title="will_apply" draggable="false" class="react-trello-board sc-htpNat dJewwL"
                 style="width: 25%;">
        </section>
    </div>
</div>

我的问题如下:我不知道为什么 React 创建了标记为问题的 div(见上面的代码片段)并且它破坏了我的 "flexbox workflow" 因为 display: flex 没有传播通过它(它显示 block)。

我有哪些选择?

我是否应该使用 display: flex; flex:1 来覆盖和设置所有 div 的样式?我可以查看创建此 div 的位置和原因吗?

也许你可以使用类似的东西来避免渲染不必要的东西div:

<React.Fragment>
 <YourComponent />
 // ... Or the component content
</React.Fragment>

额外的 div 来自 PopoverWrapperhere

该库提供了 2 种样式设置方式,如前所述 here。如果这不能满足您的需求,您需要更改代码以将 类 或样式传递给您想要设置样式的必需 DOM 元素。