javascript - How to disable button of metarial UI after one click? - Stack Overflow

I want to disable a button in my react project, where I have used MUI css framework. But now I want to

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
Add a ment  | 

2 Answers 2

Reset to default 4

You 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 }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744729762a4590397.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信