-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Simpler classful component check (fixes #458) #463
Conversation
Instead of checking for the `isReactComponent` property (which is internal to React), it seems advantageous to check for `render()`. This improves Preact support (when using recompose with non-preact-compat components) but also importantly works with components that don't inherit from `Component`.
Codecov Report
@@ Coverage Diff @@
## master #463 +/- ##
=======================================
Coverage 88.86% 88.86%
=======================================
Files 53 53
Lines 386 386
=======================================
Hits 343 343
Misses 43 43
Continue to review full report at Codecov.
|
To maintain compatibility with what he is already doing in |
^ Just saw your comment about being compatible with things that are classes but don't extend |
Thank you |
In case other library authors see this PR and adopt the same approach, I’m encouraging you not to. As noted in #538 (comment), this change was actually a major change (and broke people’s code in production). It can break code because Here is the exact algorithm React is using:
React plans to continue using this heuristic. In this sense, if for some reason your library needs to know whether a component is "newable" or not, I understand we might not be able to persuade Preact or others to adopt the same heuristic, but I hope this is helpful. |
Instead of checking for the
isReactComponent
property (which is internal to React), it seems advantageous to check forrender()
. This improves Preact support (when using recompose with non-preact-compat components) but also importantly works with components that don't inherit fromComponent
.