ReactFix
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • React
  • React Native
  • Programming
  • Object Oriented Programming

Tuesday, November 8, 2022

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

 November 08, 2022     javascript, reactjs   

Issue

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!


Solution

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



Answered By - Cameron Godwin
Answer Checked By - - Clifford M. (ReactFix Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Newer Post Older Post Home

Featured Post

Is Learning React Difficult?

React is difficult to learn, no ifs and buts. React isn't inherently difficult to learn. It's a framework that's different from ...

Total Pageviews

Copyright © ReactFix