Cameron Godwin
Cameron Godwin

Reputation: 54

How to check and handle a promise returning an array with no values

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

Answers (1)

Cameron Godwin
Cameron Godwin

Reputation: 54

array.length ? array : false - Noam (https://stackoverflow.com/users/18031894/noam)

Upvotes: 1

Related Questions