Skip to content
Advertisement

The number is not clearing up after submission even if other fields do clear up

I have these fields that I want to clear up after submission. The other fields that were stated here do clear up except for the number. Why is this happening and how do I fix this? Any help would be appreciated. Thank you.

Textfield number:

JavaScript

Clearing up the states:

JavaScript

Submission:

JavaScript

Update: I tried setting up setNumber() and it still won’t clear up

Advertisement

Answer

Your TextField is currently uncontrolled because it doesn’t have a value property. That means when you change number, it has no effect on the TextField, because the TextField‘s content isn’t controlled by your code. To make it controlled, add value={number} to it. Then, clearInfo works correctly:

JavaScript
JavaScript

I had to make two other changes there (other than commenting out missing functions, etc.) for the snippet to work without errors:

  1. I removed the async from handleNumber because it didn’t have any await in it and unfortunately Stack Snippets using JSX don’t support async/await (because they use a really old version of Babel; please vote to fix that here).

  2. React logged a warning about disableUnderline: true in InputProps saying (in effect) to make it disableunderline: "true" instead, so I did that.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement