I'm using @react-native-material and I've got displayed listitems, as well as headers, like this for example
**one**
pink 1
**one**
purple 1
**two**
blue 2
**four**
aqua 4
But I want to try and display it so that the headers aren't repeated like
**one**
pink 1
purple 1
**two**
blue 2
**four**
aqua 4
how could I go around doing that? This is my code. (i removed some code related with apis since it's not necessary here)
const App = () => {
const [products, setProducts] = useState<ProductType[] | []>([]);
const [userProducts, setUserProducts] = useState<ProductType[] | []>([]);
const [value, setValue] = useState(' ');
const [isFocus, setIsFocus] = useState(false);
const [visible, setVisible] = useState(false);
const [productId, setProductId] = useState('');
const [product, setProduct] = useState('');
const [num, setNum] = useState('');
const [amount, setAmount] = useState('');
React.useEffect(() => {
getProducts();
getUserProducts();
console.log(userProducts);
}, []);
return (
<>
<Provider>
<ScrollView>
{userProducts.length > 0 ? (
userProducts.map(userProduct => (
<>
<Text>{userProduct.num}</Text>
<ListItem
title={userProduct.product + ' x' + userProduct.amount}
onPress={async () => {
await deleteProduct(userProduct.product_id);
console.log('deleted');
getUserProducts();
ToastAndroid.show('Done', ToastAndroid.SHORT);
}}
trailing={<Text>{userProduct.num}</Text>}
/>
</>
))
) : (
<Text>Nothing in your list yet</Text>
)}
</ScrollView>
</Provider>
</>
);
};
export default App;
const styles = StyleSheet.create({
dropdown: {
height: 50,
borderColor: 'gray',
borderWidth: 0.5,
borderRadius: 8,
paddingHorizontal: 8,
},
row: {
flexDirection: 'row',
flexWrap: 'wrap',
},
});