question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Autocomplete is changing the uncontrolled value state to be controlled.

See original GitHub issue

Describe the bug Autocomplete is changing the uncontrolled value state to be controlled when choosing option

To Reproduce Steps to reproduce the behavior:

  1. Go to codesandbox
  2. Try choose any option
  3. See console.

Expected behavior Shouldn’t change state

I think this is due to the fact that the defaultValue remains undefined if getOption was passed but value was not.

Maybe set to null by default, because from react-final-form:

By default, if your value is null, <Field/> will convert it to ‘’, to ensure controlled inputs

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:22 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
lookfirstcommented, Oct 11, 2022

@Lucas-Alf Thanks for the update. I’ve reopened for now until myself or someone else can find the time to investigate this further.

2reactions
Lucas-Alfcommented, Oct 11, 2022

I had a similar problem trying to create a Autocomplete component with server side data fetch. Try to remove this line and see if stops giving that error: https://github.com/lookfirst/mui-rff/blob/646a5393705093508fad8acedecbdda11584d0b7/src/Autocomplete.tsx#L150

Looks like is something with the defaultValue equals to undefined. For my custom component i just removed this line and the problem is gone, i really don’t need the defaultValue in my use case.

If someones wants see my component (not TS): https://github.com/Lucas-Alf/resoar/blob/main/src/components/AutocompleteServerSide/AutocompleteAdapter.jsx

Read more comments on GitHub >

github_iconTop Results From Across the Web

A component is changing an uncontrolled Autocomplete to be ...
If you pass value={undefined} to the Autocomplete component, it will start in "uncontrolled" mode, meaning it keeps its own internal state.
Read more >
[Autocomplete] "A component is changing the controlled value ...
Material-UI : A component is changing the controlled value state of Autocomplete to be uncontrolled. Elements should not switch from ...
Read more >
A component is changing an uncontrolled input to be controlled
The warning: A component is changing an uncontrolled input to be controlled. This is likely caused by the value changing from undefined to...
Read more >
A component is changing an uncontrolled Autocomplete to be ...
These two state are isolated, they should be controlled independently. Component becomes uncontrolled when inputValue property is undefined, and vice versa.
Read more >
a component is changing the uncontrolled value state of ...
The warning "A component is changing an uncontrolled input to be controlled" occurs when an input value is initialized to undefined but is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found