First, I am from Web World(ReactJS), so not familier in React Native.
How to know which button was clicked?
Example:
const [titleOne, setTitleOne] = useState('A button 1');
const [titleTwo, setTitleTwo] = useState('A button 2');
const handlePress=(event)=>{
/*
if first button clicked,
I want to write: setTitleOne(Button 1 clicked);
if second button clicked,
I want to write: setTitleTwo(Button 2 clicked);
*/
}
<View>
<Button title={titleOne} onPress={handlePress} />
<Button title={titleTwo} onPress={handlePress} />
</View>
Thanks in advance.
2
Answers
By passing an extra arg say
name
…