A React range slider that will not move or does not update its value
You provided a `value` prop to a form field without an `onChange` handler. This will render a read-only field. If the field should be mutable use `defaultValue`. Otherwise, set either `onChange` or `readOnly`.Short answer
A React range slider that will not move is almost always a controlled input: you passed value but no onChange, so React keeps resetting the thumb. Other causes are state that starts undefined, a value that arrives as a string, and min, max or step defaults of 0, 100 and 1 that clamp your number. Open the console first, React names the problem.
Fix it fast
1Find out which cause you have
Open the browser console and drag the slider. If React prints the read-only warning, go to the first cause. If the console is quiet and the thumb jumps to an end or the numbers look wrong, look at the last two causes.
// temporary line inside the change handler console.log(typeof e.target.value, e.target.value);2Match what you see, then jump to its fix
- 1
You provided a `value` prop to a form field without an `onChange` handlerThe slider is controlled but has no onChangeFix - 2
A component is changing an uncontrolled input to be controlledThe state starts as undefined or nullFix - 3
The slider moves, but arithmetic with the value gives results like "5010" instead of 60The value arrives as a stringFix - 4
The thumb stops at the far right even though the state holds a larger value, or decimals are rounded awaymin, max or step do not fit your numbersFix
- 1
What does the error look like?
You provided a `value` prop to a form field without an `onChange` handler. This will render a read-only field. If the field should be mutable use `defaultValue`. Otherwise, set either `onChange` or `readOnly`.A component is changing an uncontrolled input to be controlled
Cause 1 of 4
The slider is controlled but has no onChange
1Check
Passing value makes React the owner of what the input shows. With no handler that updates it, every drag is undone and the field is read-only.
grep -rn 'type="range"' src2Fix
Keep value and add an onChange that stores the new value. If you only want a starting position, use defaultValue instead.
const [volume, setVolume] = useState(50);
<input
type="range"
min={0}
max={100}
value={volume}
onChange={(e) => setVolume(e.target.valueAsNumber)}
/>
// starting position only, no state
<input type="range" defaultValue={50} />3Verify
Drag the thumb. It follows the pointer, the console warning is gone, and the value read in the console changes.
document.querySelector('input[type=range]').valueConfirmed by react.dev
Cause 2 of 4
The state starts as undefined or null
1Check
While value is undefined, React treats the input as uncontrolled. When state later fills in, it flips to controlled and React warns. This happens when the starting number comes from an API or from useState() with no argument.
grep -rn 'useState()' src2Fix
Give the state a real starting value, or fall back at the point of use. A controlled input must keep getting a value of one type for its whole life.
const [volume, setVolume] = useState(50);
// or, for a value that loads later
<input type="range" value={settings.volume ?? 50} onChange={onChange} />3Verify
Reload the page. The warning no longer appears when the data arrives, and the input still shows a value.
document.querySelector('input[type=range]').valueConfirmed by react.dev
Cause 3 of 4
The value arrives as a string
1Check
The value of a range input is a string holding the number. Adding 10 to the string "50" joins text instead of adding.
console.log(typeof e.target.value);2Fix
Read the number straight from the element with valueAsNumber, or convert with Number().
onChange={(e) => setVolume(e.target.valueAsNumber)}
// or
onChange={(e) => setVolume(Number(e.target.value))}3Verify
Log the state after a drag. It should print a number.
console.log(typeof volume, volume + 10);Confirmed by developer.mozilla.org
Cause 4 of 4
min, max or step do not fit your numbers
1Check
Without attributes a range input runs from 0 to 100 in steps of 1. A value above max is set to max, one below min is set to min, and a value that does not fit the step may be rounded.
grep -rn 'type="range"' src | grep -v max2Fix
Set min, max and step to match the range you really want, including a decimal step for fractions.
<input
type="range"
min={0}
max={500}
step={0.5}
value={price}
onChange={(e) => setPrice(e.target.valueAsNumber)}
/>3Verify
Set the state to a value inside the new range and read the number back from the element in the console.
document.querySelector('input[type=range]').valueAsNumberConfirmed by developer.mozilla.org
How do I stop it coming back?
- Treat every input that has a value prop as a pair: value plus onChange, written in the same edit.
- Initialise slider state with a number of the right type, never undefined or null.
- Always write min, max and step on a range input, so the numbers in your code and the numbers on screen agree.
- Convert at the edge: turn the string into a number inside the handler and keep numbers in state.
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