Search code examples
typescriptreact-nativesearchbar

If Else Statement for SearchParams [React Native]


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>
)}

Solution

  • {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