简体   繁体   中英

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.

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. And when render is called on an element, it is also called on all its child elements.

Additionally, don't use inheritance. React components extend React.Component , they never extend other components.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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