Allow null
values in trailing and leading actions
#40
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.
What
This pull requests adds a
React.isValidElement
check right before the trailing and leading elements are cloned.Why?
Without this, any child that is passed will automatically be cloned, even if it is not a valid React element. If that is the case, a fatal error will be thrown, breaking the entire application.
This pull request fixes that by simply returning the child as-is if it is not a React element.
Use cases?
I came across this issue because I want to conditionally show certain actions. Right now, it's impossible to do it like this:
If ONE of these conditions is false, I would expect the other element to still be rendered. This is not the case, because the returned
null
is seen as a child, which is subsequently cloned (causing an error).