英文:
How to make a button non-working until another React Native TypeScript button is pressed
问题
我有这样一个问题,我需要代码,这样在按下一个按钮后,另一个React Native TypeScript按钮就可以用于按下。
我尝试了许多方法,但没有什么效果。
英文:
I have such a problem, I need code so that after pressing one button, another React Native TypeScript button is available for pressing
I tried many things, but nothing came out
答案1
得分: 0
你需要跟踪一些信息,如何实现依赖于上下文。
但在渲染期间,您需要知道按钮是否已被按下。最基本的形式如下:
const [hasBeenPressed, setHasBeenPressed] = useState(false)
然后,当第一个按钮被点击时,您需要执行按钮所需的操作,同时调用 setHasBeenPressed(true)
。
第二部分是使用 hasBeenPressed
以某种方式影响第二个按钮。最简单的形式是:
<button disabled={!hasBeenPressed}/>
我不了解 React Native 按钮的具体情况。
这只是一个简单的示例,如果您想进一步探讨,也许您可以根据第一个按钮可能已经更改或由其他方式设置的一些数据来决定第二个按钮是否应禁用,但这些都是更多的细节。希望这可以帮助您入门。
英文:
You will need to keep track of some information, how you do it can depend on the context.
But essentially during the rendering you need to know whether the button has been pressed or not. The most basic form of this would be
const [hasBeenPressed, setHasBeenPressed] = useState(false)
Then when the first button gets clicked you do whatever the button needs to do plus call setHasBeenPressed(true)
The second part is using hasBeenPressed
to in some way affect the second button. Again in the simplest form would be <button disabled={!hasBeenPressed}/>
. I don't know about React Native button specifically.
This was as a simple example, if you want to look at it further, maybe you can derive whether the second button should be disabled or not based on some data that may have changed or been set by the first button or some other way, but those are more details. Hopefully this can get you started.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论