in this case, it will trigger render again when I call updateNumber(), so how can create the valuable that it is for saving data only?
function test() {
const [cartNum, setCartNum] = useState(0);
function updateNumber() {
setCartNum(number +1);
}
return (
<View style={{ flex: 1 }}>
<TouchableOpacity onPress={updateNumber}>
<Text>
{Math.random()}
</Text>
</TouchableOpacity>
</View>
);
}
2
Answers
Use the
useRef
hookExample below
There are 2 ways for it to update and not re render:
Hope it helps. feel free for doubts