In my react-native applications, i had written a code like this.
return (
<PersonHandler
profilePicture={item.user.profileImage ? {uri: item.user.profileImage} : DefaultUser}
firstName={item.user.firstName}
lastName={item.user.lastName}
buttonBorderColor={item.status === 0 ? "#000000" : "#37CAFA"}
buttonBackgroundColor={item.status === 0 ? null : "#37CAFA"}
buttonTextColor={item.status === 0 ? "#000000" : "#FFFFFF"}
buttonText={item.status === 0 ? USER_STATUS.REQUESTED : USER_STATUS.FOLLOWING}
submitting={unfollowIsInProgress && item._id === unfollowingPerson._id}
onButtonPress={() => this.onUnfollowPress(item)}
/>
);
Now I have more than 2 statuses to handle, so the ternary operator here cannot be used. What will be the best approach to handle a situation like this?
I have 3 statuses now. 0, 1 and 2. According to the status I have to handle the following conditions.
buttonBorderColor={item.status === 0 ? "#000000" : "#37CAFA"}
buttonBackgroundColor={item.status === 0 ? null : "#37CAFA"}
buttonTextColor={item.status === 0 ? "#000000" : "#FFFFFF"}
buttonText={item.status === 0 ? USER_STATUS.REQUESTED : USER_STATUS.FOLLOWING}