RetroFed Forum
Your home away from modern life.
Count child elements HOC
Post Reply
AuthorMessage
zamithal programming.dev zamithal@programming.dev
Joined: 2023-11-03
Quote

I'm looking to write an HOC that counts and prints to the console the number of

elements in the wrapped component. For example:

const Foo: FC<{}> = ({}) => {
    return (
        <div>
            <h1>Foo</h1>
            <p>Bar</p>
        </div>
    )
}


export default countH1(Foo)

this should print 1 and then return Foo as is for rendering.

React.Children.forEach(child => {...})

seems to be about the explicit children property and not descendant html elements. How can I achieve this?

1   Original
Post Reply
Back to top