0

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
}

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Hmmmmmmm I'm doing some pretty intense sh*t (basically making a better version of Radium that works with react-native), so I think this might be an exception to never calling render. I'd like to render the entire tree of components and get all of their style properties and then process them, but render only goes one-level deep.
Render goes all the way down the tree, but the benefit of React is that it doesn't needlessly re-render things that have not changed. If you're seeing that items are not re-rendering, it means that they should display the same thing so there was no need to render. If for whatever reason you need them to render at specific times, then React is probably a bad choice, as you're actively going out of your way to undo the main thing that makes it special.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.