DEV Community

Cover image for React setState without Render
Ertugrul DOGAN
Ertugrul DOGAN

Posted on

React setState without Render

Since setstate is defined in onpress, it renders again and the ones with input are deleted.

<View style={styles.container}>
<View>
<Text>TAKSİT SEÇENEKLERİ</Text>
</View>
{this.state.List.map((item, key) => {
return (
<TouchableOpacity
style={styles.paymentItemTaksit}
key={key}
onPress={() => {
this.setState({
checked: key,
taksitsayisi: item.value,
surcharge: (cart.total * item.value) / 100,
});
}}>
<View style={styles.shippingItemTitle}>
{this.state.checked === key ? (
<View>
<Icon
name="radio-button-checked"
style={styles.checkIcon}
/>
{item.value == 1 ? (
<Text style={styles.paymentItemText}>
{item.taksit} {cart.total} {cart.total}
</Text>
) : (
<Text style={styles.paymentItemText}>
{item.taksit}{' '}
{(
(cart.total + (cart.total * item.value) / 100) /
item.value
).toFixed(2)}{' '}
{(
cart.total +
(cart.total * item.value) / 100
).toFixed(2)}
</Text>
)}
</View>
) : (
<View>
<Icon
name="radio-button-unchecked"
style={styles.uncheckIcon}
/>
{item.value == 1 ? (
<Text style={styles.paymentItemText}>
{item.taksit} {cart.total} {cart.total}
</Text>
) : (
<Text style={styles.paymentItemText}>
{item.taksit}{' '}
{(
(cart.total + (cart.total * item.value) / 100) /
item.value
).toFixed(2)}{' '}
{(
cart.total +
(cart.total * item.value) / 100
).toFixed(2)}
</Text>
)}
</View>
)}
</View>
</TouchableOpacity>
);
})}
</View>

Top comments (0)