v6: prefer components in normalizeComponent #1609
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We have been using v6.10.0 and one of our cell components was changed to use
React.memo
and the table unexpectedly stopped working. It looks like other have users reported issues withnormalizeComponent
in various versions and some fixes have been made.Unfortunately some users have code that assumes the "components" are just a element factory and not a true React component. When these React components are defined inline this can cause unmounts when the parent component is re-rendered. This branch will not fix that issue but I think instead users should avoid creating inline components and just use React context if you absolutely need to provide anything to these components.
The fix for us was to use
isValidElementType
fromreact-is
for component detection and allow us to useReact.memo
,React.forwardRef
, etc. We think this solution is cleaner and providers a more predictable API. We weren't comfortable with the existingString(component).includes('.createElement')
detection and have a lot of examples where that fails.I understand that this probably won't be merged but it could be helpful for others that might fork this lib. Thanks!
Other changes
prop-types
peer dep to^15.7.0
because that is whenelementType
was introducedreact-is
peer depnormalizeComponent