Reputation: 54
I'm working on a project where a map function is filtering through a database to return an array holding ids to be rendered on a react return. Sometimes the map filter will return no ids in which-case I want to instead just render a <p>
tag or something to inform the user that there was nothing to return, and I want to do this with an inline if statement in a react return fragment.
Right now, if there is nothing to render, the map filter function returns an array of (0), I want to check for this response to set a useState()
to false so I can prompt the aforementioned render message.
Thanks in advance!
Upvotes: 0
Views: 30
Reputation: 54
array.length ? array : false
- Noam (https://stackoverflow.com/users/18031894/noam)
Upvotes: 1