首先,我来自网络世界(ReactJS),所以对React Native不熟悉。
如何知道单击了哪个按钮?
示例:
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>
提前感谢
2条答案
按热度按时间nxagd54h1#
2wnc66cl2#
通过传递一个额外的参数,例如
name
...