admin管理员组文章数量:1391974
I want to disable a button in my react project, where I have used MUI css framework. But now I want to know how can I disable button after one click.
<Button variant="contained"
onClick={()=>handleAdd(course)}
disabled=?
>
I want to disable a button in my react project, where I have used MUI css framework. But now I want to know how can I disable button after one click.
<Button variant="contained"
onClick={()=>handleAdd(course)}
disabled=?
>
Share
Improve this question
edited Sep 25, 2022 at 12:37
MD. Istiak Shamim Shishir
asked Sep 25, 2022 at 12:37
MD. Istiak Shamim ShishirMD. Istiak Shamim Shishir
211 silver badge3 bronze badges
1
- Have you even tried to find it ? React Materials-UI disable a button in a handler – debugger Commented Sep 25, 2022 at 12:44
2 Answers
Reset to default 4You want to create a new state using useState hook named for example isClicked and change your handleAdd function to set the state to true after a click.
const [isClicked, setIsClicked] = useState(false);
Then in your handleAdd method add something like:
if(!isClicked) setIsClicked(true)
And finaly in your Button ponent, set disabled to this state.
disabled = {isClicked}
Hope this helps :).
disabled={currentGroupForm.name?.length === 0 ||
currentGroupForm.sapNumber?.length === 0 }
本文标签: javascriptHow to disable button of metarial UI after one clickStack Overflow
版权声明:本文标题:javascript - How to disable button of metarial UI after one click? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744729762a2621978.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论