React Native:Press上更改组件道具
我试图更改单击的按钮的道具:
如果单击超过3次,我想将其禁用。
这是我的代码:
import React, { useState } from 'react';
import { Button, Text, View } from 'react-native';
const App = () => {
const [pressedCount, setPressedCount] = useState(0);
return (
<View style={{ flex: 1, justifyContent: 'center' }}>
<Text style={{ margin: 16 }}>
{pressedCount > 0
? `The button was pressed ${pressedCount} times!`
: 'The button isn\'t pressed yet'
}
</Text>
<Button
title='Press me'
onPress={() => if (pressedCount>=3){Button.setState.({disabled:true})} else{setPressedCount(pressedCount+1)}}
/>
</View>
);
};
export default App;
我已经尝试了(persedCount&gt; = 3){button.props.disabled = true} else {setPressedCount(persedCount+1)}}},但相同。
关于如何正确执行此操作的任何建议?
Im trying to change the props of the button which is clicked :
if clicked more than 3 times, i want to disable it.
Here is my code :
import React, { useState } from 'react';
import { Button, Text, View } from 'react-native';
const App = () => {
const [pressedCount, setPressedCount] = useState(0);
return (
<View style={{ flex: 1, justifyContent: 'center' }}>
<Text style={{ margin: 16 }}>
{pressedCount > 0
? `The button was pressed ${pressedCount} times!`
: 'The button isn\'t pressed yet'
}
</Text>
<Button
title='Press me'
onPress={() => if (pressedCount>=3){Button.setState.({disabled:true})} else{setPressedCount(pressedCount+1)}}
/>
</View>
);
};
export default App;
I've tried if (pressedCount>=3){Button.props.disabled=true} else{setPressedCount(pressedCount+1)}} but it's the same.
Any advice on how to properly do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)