【发布时间】:2020-12-17 13:56:47
【问题描述】:
我在使用库 react-input-range(或任何其他滑块)时遇到问题:我可以看到 console.log(value) 时该值正在正确更改,但是当我移动它时滑块没有移动……不管是不是通过道具。
有什么想法吗?
import React from 'react';
import InputRange from 'react-input-range';
interface Props {
min:number;
max:number;
step?:number;
value:any;
id:string;
}
const RangeSlider = ({ min, max, step=1, value, id }: Props) => {
function onValueChange(newval: any){
console.log(newval);
value=newval;
//some other actions here
}
return (
<div className="slider m-4 mb-6">
<InputRange
minValue={min}
maxValue={max}
step={step}
onChange={onValueChange}
value={value}
/>
</div>
);
};
export default RangeSlider;
【问题讨论】:
-
将值移动到本地状态,因为每次状态更改都会重新呈现。