MUI Autocomplete warns that the value matches no option
MUI: The value provided to Autocomplete is invalid.Short answer
Autocomplete compares its value with the options using strict equality. It warns when the value is not one of the option objects, for example a fresh object from your form state or an id such as 0. Pass the matching option, add isOptionEqualToValue to compare by id, and treat typed text separately if freeSolo is on.
Fix it fast
1Find out which cause you have
Print the value and the options side by side. The warning names the value it could not find. See whether it is an id, a text string or an object that merely looks like one of the options.
console.log('value', value); console.log('options', options);2Match what you see, then jump to its fix
- 1
The value is an object you can find in the options by its id, yet the warning staysThe value is an object, but not the same object as an optionFix - 2
The warning names a number or an empty string, as in None of the options match with `0`The value is a bare id or a placeholder like 0, not an optionFix - 3
The warning appears after the user types a value that is not in the listfreeSolo lets users type text, but the options are objectsFix
- 1
What does the error look like?
MUI: The value provided to Autocomplete is invalid.None of the options match with `0`
Cause 1 of 3
The value is an object, but not the same object as an option
1Check
Without isOptionEqualToValue, the value must have reference equality with an option. Values rebuilt from an API response, from form defaults or from JSON.parse are new objects, so they never equal the options.
console.log(options.includes(value), options.some(o => o.id === value?.id))2Fix
Tell Autocomplete how to compare. Match on a stable field such as id.
<Autocomplete
options={options}
value={value}
getOptionLabel={(o) => o.name}
isOptionEqualToValue={(option, val) => option.id === val.id}
onChange={(_, next) => setValue(next)}
/>3Verify
The warning no longer shows in the console and the saved choice appears in the input when the form loads.
console.log(options.some(o => o.id === value?.id))Confirmed by mui.com
Cause 2 of 3
The value is a bare id or a placeholder like 0, not an option
1Check
The value prop is the option itself, not its id. A form default of 0 can never reference any item in the list.
console.log(typeof value, options.find(o => o.id === value))2Fix
Keep the whole option in state, or turn the id into its option before you pass it.
const selected = options.find((o) => o.id === form.categoryId) ?? null;
<Autocomplete
options={options}
value={selected}
getOptionLabel={(o) => o.name}
onChange={(_, next) => setForm({ ...form, categoryId: next?.id })}
/>3Verify
Load the form with an existing id and with none. Neither case prints the warning.
console.log(selected)Confirmed by mui.com
Cause 3 of 3
freeSolo lets users type text, but the options are objects
1Check
With freeSolo, the value created by typing is always a string, whatever the type of the options. MUI warns that non-string options can then cause a type mismatch.
grep -rn "freeSolo" src/2Fix
Either turn freeSolo off so only listed options are valid, or keep strings and objects apart in your onChange handler.
<Autocomplete
freeSolo
options={options}
getOptionLabel={(o) => (typeof o === 'string' ? o : o.name)}
onChange={(_, next) =>
typeof next === 'string' ? setCustom(next) : setValue(next)
}
/>3Verify
Type a new word and pick a listed option. Both paths work without a console warning.
console.log(typeof next)Confirmed by mui.com
How do I stop it coming back?
- Store the selected option, or look it up by id every render, instead of keeping a copy of it.
- Always set isOptionEqualToValue when options come from an API.
- Keep value referentially stable: MUI says its reference should change only when the value itself changes.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
Module not found for antd/dist/antd.less after upgrading to Ant Design 5
Module not found: Error: Can't resolve 'antd/dist/antd.less'
Ant Design 5 dropped Less and the bundled CSS file for CSS-in-JS, so antd/dist/antd.less no longer exists.
3 causes, each with a fixWeb apps
Astro Code component fails inside a React component
Astro components cannot be rendered directly via function call
Astro components such as Code only exist on the server and render static HTML.
2 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
How to catch and handle a 422 from Axios in a Redux thunk
action.error.message is 'Rejected' and action.payload is undefined
A 422 means the server read the request but cannot process its content, so repeating it unchanged fails again.
4 causes, each with a fixWeb apps
axios gets 429 Too Many Requests from a React app
429 (Too Many Requests)
A 429 comes from the server or an API gateway, not from axios: your client sent too many requests in a window.
4 causes, each with a fixWeb apps
Axios request is not cancelled when a React component unmounts
A cancelled request is logged as an error in the catch block
Axios cancels a request when you pass it an AbortSignal and later call abort() on its controller.
4 causes, each with a fix