1

My state start 0 initial, I want to use TextField in my form. It's type number and increment or decrement. When I click it gets 2 (state).

<TextField
 id="outlined-number"
 label="Quantity"
 value={value}
 onChange={(ev) => handleChange(ev)}
 type="number"
 className={classes.textField}
 InputLabelProps={{
    shrink: true,
 }}
 margin="normal"
 variant="outlined"/>

I did a lot of search in stackoverflow, 1 2 But my problem not solved.

I tried 1:

onChange={handleChange}

2:

 ev.stopPropagation();

My handler function :

    const [value, setValue] = useState(0);

    function handleChange(ev) {
        setValue(ev.target.value);
    } 

It's start 0, When I clicked UP button and than changed 2. I don't understand where I made a mistake. Thanks for answer.

code : https://github.com/kvlknctk/cekilis/blob/volkancatak/src/app/main/market/AlertDialog.js

Kvlknctk
  • 634
  • 12
  • 27

1 Answers1

0

if you are using create-react-app then your Appcomponent is wrapped in StrictMode like this:

<React.StrictMode>
  <App />
</React.StrictMode>,

go to index.js and remove <React.StrictMode></React.StrictMode>

https://github.com/facebook/react/issues/12856#issuecomment-390206425

Dory Daniel
  • 798
  • 14
  • 21