-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
If/Else does not catch all scenarios #18
Comments
Shouldn't it be |
I had tried swapping |
@jonfairbanks Sorry for the late reply. This happens because React eagerly evaluates all children, which means that even if the condition is falsy, the code inside of the To work around that, you can wrap the children of the <If condition={this.props.ticket === null}>
<Then>
<div id="noData" style={style.noData}>
No details found for the given ticket
</div>
</Then>
<Else>{function() {
return this.props.ticket.map(function(data,i) {
return (
// Do something with this.props.ticket here
)
}, this)
}}</Else>
</If> I will soon update the README to both warn again against that issue and emphasize the solution above. |
@jonfairbanks I'm closing the issue, feel free to re-open it if needed. |
Ah, I was not aware of that. Will try moving the logic into a function. Thanks @romac! |
@romac: Unfortunately the function approach still does not catch this use-case. (I do not have the option to re-open this issue.) |
I have ran into a scenario that react-if doesn't seem to handle appropriately.
In my case, I have a props which has been verified to be equal to
null
. As seen above, I have created an if condition to not show data if the props is null.However, regardless of this logic, the
this.props.ticket.map
inside<Else>
is run in all cases. This then leads to aTypeError: Cannot read property 'map' of null
error which prevents our app from rendering.The text was updated successfully, but these errors were encountered: