I have this simple component in React-Native, My goal is to skip the iteration if the given argument gradeIsMandatory is false, it should only iterate over warranty and price, How can I achieve this result without affecting performance? I will take any advice thanks
import React, { useCallback } from 'react';
import { View, Text, SafeAreaView, SectionList, StyleSheet, Image, TouchableOpacity, Alert} from 'react-native';
export const ModalHeader: React.FC<{}> = () => {
const gradeIsMandatory = false
//code I tried to use
useEffect(()=>{
if(!gradeIsMandatory){
let appendGrade = { key: 'grade', title: 'Grade' }
modalTabs.push(appendGrade)
}
},[])
return (
<View>
<View>
<View>
{modalTabs.map((tab, i) => (
<TouchableOpacity>
<Text>{tab.title}</Text>
</TouchableOpacity>
))}
</View>
</View>
</View>
);
}
const modalTabs = [
{ key: 'warranty', title: 'Your Waranty' },
{ key: 'price', title: 'Your price' }
]
filter, notmap.items.filter(shouldIKeep).map(renderJSX).