1

I am trying to do an inline conditional rendering like the following:

 {var && <MyComponent />}

but it throws me this error:

Text strings must be rendered within a <Text> component

However when I do it like this:

{var !== '' && <MyComponent/ >} It works perfectly fine.

Any idea why this happens?

1 Answer 1

1

That's because empty string will be rendered in the component as it's a falsy value (because && will return short-circuit value). And in react-native you can't render a string without wrapping it in Text component.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.