0

I am new to React Native and I am using typescript for React Native. Currently, I am having a difficulty to do if else statement for search function. Below is my code for if else statement for search function.

{searchParams !== "" (
  <View>
    <Text>Sorry, error occur</Text>
  </View>
  ) : (
  <View>
    <Text>Success!</Text>
  </View>
)}
Roseanne
  • 67
  • 1
  • 1
  • 7

2 Answers2

1
{searchParams !== "" ? (
  <View>
    <Text>Sorry, error occur</Text>
  </View>
  ) : (
  <View>
    <Text>Success!</Text>
  </View>
)}

You're missing a question mark: https://stackoverflow.com/a/10270383/11760094

Elliot Hesp
  • 503
  • 3
  • 8
0
{searchParams !== "" ?
  <View>
    <Text>Sorry, error occur</Text>
  </View>
   : 
  <View>
    <Text>Success!</Text>
  </View>
}

here is the link if-else statement inside jsx: ReactJS

Asad
  • 563
  • 3
  • 16