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 }
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744729762a4590397.html
评论列表(0条)