ReactJs: Prevent multiple times button press

前端 未结 9 967
别跟我提以往
别跟我提以往 2020-11-27 13:21

In my React component I have a button meant to send some data over AJAX when clicked. I need to happen only the first time, i.e. to disable the button after it\'s first use.

9条回答
  •  春和景丽
    2020-11-27 13:56

    You can try using React Hooks to set the Component State.

    import React, { useState } from 'react';
    
    const Button = () => {
      const [double, setDouble] = useState(false);
      return (
        

    Make sure you are using ^16.7.0-alpha.x version of react and react-dom.

    Hope this helps you!

提交回复
热议问题