简体   繁体   English

如何从React组件中渲染整个树?

[英]How to render whole tree from within React component?

I'm building a higher-order component, and I'd like it to render out all of the composed component's children, and their children, all the way down the line. 我正在构建一个更高阶的组件,我希望它可以将组成的所有子组件及其子组件一路渲染。

When I call render(), though, it only renders the component's children, not their children's children. 但是,当我调用render()时,它仅呈现组件的子代,而不是子代的子代。

How do I render it all the way down? 如何将其一直渲染?

Here's some code: 这是一些代码:

export default ComposedComponent => {
  class HoC extends ComposedComponent {
    render() {
      console.log(super.render())
    }
  }

  return HoC
}

You never call render manually. 您永远不会手动调用渲染。 Render is automatically called upon initialisation, and every time the props and state change. 初始化时以及每次propsstate更改时,都会自动调用渲染。 And when render is called on an element, it is also called on all its child elements. 当在某个元素上调用render时,它的所有子元素上也会被调用。

Additionally, don't use inheritance. 此外,请勿使用继承。 React components extend React.Component , they never extend other components. React组件扩展了React.Component ,它们从不扩展其他组件。

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

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