愿所有的美好和期待都能如约而至

如何操作子对象的渲染输出

发布时间:  来源:互联网  作者:匿名  标签:error How to manipulate child's render output exception frontend IT资讯 j  热度:37.5℃

本文介绍了如何操作子对象的渲染输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用来自第三方库的组件,并且我想操作呈现输出。

假设我们有两个组件:

// third party component that I don't have access to its code
const ThirdPartyComponent = () => (
  <div>
    <span>
      ...
    </span>
  </div>
)


// My component using the third party component
const MyComponent = () => (
  <div className="wrapper">
    <ThirdPartyComponent />
  </div>
)

通常输出为:

<div class="wrapper">
  <div>
    <span>
       ...
    </span>
  </div>
</div>

现在我要操作第三方组件,使我的组件呈现以下内容:

<div class="wrapper">
  <span>
    ...
  </span>
</div>

或换句话说从不需要的<div />元素中解开呈现的内容

1.我无法更改第三方代码

2.子组件不转发ref

您知道怎么做吗?

勇敢去编程!

勇敢的热爱编程,未来的你一定会大放异彩,未来的生活一定会因编程更好!

TOP