I've found a few similar questions on thit topic but they're usually about React and not React Native specifically and I'm finding it a bit difficult to translate them as very new to both coming from an Android/Java background. I've a component that holds a plus and a minus icon to increase/decrease their counter. This component is used multiple times however, and I don't want to have a total and a setTotal for each instance of this component so that each can have their own total updated independently of any of the other components. At the moment, they all update when I click any of the plus/minus signs. I'm using hooks.
const [total, setTotal] = useState(0)
const increase = () => {
setTotal(total + 1)
}
const decrease = () => {
setTotal(total - 1)
}
...
<Reportable
title={'First'}
decrease={decrease}
increase={increase}
total={total}
onPress={handleChange}
/>
<Reportable
title={'Second'}
decrease={decrease}
increase={increase}
total={total}
/>
Thanks very much.