react-jsx reactjs redux string

Check for empty string in JSX

Is there a way in React/JSX to check if a user’s input string is empty?


{(( ==" ")||(""))? 

This condition works when a user inputs nothing or an empty string that is 1 space long, but if the empty string is more than 1 space long it fails. Is there a trick with JSX to check this or should I handle this in my reducer?

You could check for trimmed string:

{ == ""}

This trims the string (which removes whitespace and newlines) and then check is if it’s an empty string. Here’s a CodePen demonstration.