I saw on React there is a flag to check current component is a class or a stateless component.
Here it is, .isReactComponent
Currently, I'm trying to make a preact tree walker to fetch data on the server (SSR), therefore I make a recursive function to walk on every preact component, and now I'm struggling to check if the current component is stateless or class-based (I'm using react-router v4)
Thanks
Hey @alfrcr thanks for the issue. Checking for the existence of the render function is an acceptable way to determine if a component is a class Component. This method is used in acdlite/recompose to detect if a component is a class, see https://github.com/acdlite/recompose/commit/1c9cf7b1ac75fb1a65a4db9a5a0fe2344ad97c2d.
I think the isClassComponent function from recompose will be able to solve your problem.
Hi @pl12133
I never had a thought that I can use Component.prototype.render to check the component is class-based or not.
Thanks, @pl12133
Most helpful comment
Hi @pl12133
I never had a thought that I can use
Component.prototype.renderto check the component is class-based or not.Thanks, @pl12133