My current if/else statement in React Native is functional but seems verbose. I am curious to know how other developers would optimize and shorten it.
I feel like my code represents a beginner's approach, and I welcome suggestions on how to improve it.
Just to clarify, I am working with React Native for this project.
getBatteryIcon() {
if (this.props.batteryLevel >= 81 && this.props.batteryLevel <= 100) {
return (
<Image
source={require('./../../../android/app/src/main/res/drawable/batterylevel_four.png')}
/>
)
} else if (this.props.batteryLevel >= 51 && this.props.batteryLevel <= 80) {
return (
<Image
source={require('./../../../android/app/src/main/res/drawable/batterylevel_three.png')}
/>
)
} else if (this.props.batteryLevel >= 25 && this.props.batteryLevel <= 50) {
return (
<Image
source={require('./../../../android/app/src/main/res/drawable/batterylevel_two.png')}
/>
)
} else {
return (
<Image
source={require('./../../../android/app/src/main/res/drawable/batterylevel_one.png')}
/>
)
}
}