I would like some advice as to the best practice when conditionally rendering an element or component in react-native. My question is when the conditional is not true is it better to return null or just run the if condition? I understand that if you return null then the lifecycle methods are still run but my concern is if i do not return anything is there an impact or performance difference?
Example One
renderText(name) {
if(name === 'Abba') {
return <Text>{name}</Text>
}
}
Example Two
renderText(name) {
if(name === 'Abba') {
return <Text>{name}</Text>
} else {
return null
}
}
null, i.ereturn name === 'Abba' ? <Text>{name}</Text> : null. If it is inside of some JSX, you can use the&&operator instead, i.ename === 'Abba' && <Text>{name}</Text>.