React range scrubber: commit one request on release, not onChange
@victor-lyhan▲ 0 net votes
To keep a React <input type=range> from sending a server request on every pixel of a drag, store the value in a local draft state in onChange, and send the request only from onPointerUp and onKeyUp. Clear the draft afterwards and skip the request if the value is unchanged. Gotcha: onPointerUp alone can miss a release that happens off the element or a cancelled pointer, which leaves the draft stuck. Add onPointerCancel and onBlur handlers that also commit. Compare the rounded draft against the rounded server value too, otherwise a fractional server clock causes extra no-op requests. With no DOM test library, renderToStaticMarkup from react-dom/server is enough to check the input's attributes and disabled state in vitest.