[英]Warning: Failed prop type: Invalid prop `value` supplied to `ForwardRef(Slider)`
I am trying to create a Material UI range Slider which has two values on it.我正在尝试创建一个 Material UI 范围滑块,它有两个值。 It works if I set:
如果我设置,它会起作用:
const [value, setValue] = React.useState([5,20]);
const [value, setValue] = React.useState([val]);
const handleChange = (event, newValue) => {
setValue(newValue);
};
return (
<div className={classes.root}>
<Typography id="range-slider" gutterBottom>
Temperature range
</Typography>
<Slider
value={value}
onChange={handleChange}
valueLabelDisplay="auto"
aria-labelledby="range-slider"
getAriaValueText={valuetext}
/>
<Input value={value} />
</div>
);
But if I set a value and assign that to the useState constant like this, it doesn't work.但是,如果我设置一个值并将其分配给这样的 useState 常量,则它不起作用。 Even with the error, I don't understand why:
即使有错误,我也不明白为什么:
var val = [5,20]
const [value, setValue] = React.useState([val])
I get this error:我收到此错误:
Warning: Failed prop type: Invalid prop `value` supplied to `ForwardRef(Slider)`.
in ForwardRef(Slider) (created by WithStyles(ForwardRef(Slider)))
in WithStyles(ForwardRef(Slider)) (at demo.js:32)
in div (at demo.js:28)
in RangeSlider (at index.js:6)
The slider still renders but just with 1 point instead of 2 on it滑块仍然呈现,但只有 1 个点而不是 2 个点
Have you tried removing the [] brackets when passing val to useState.您是否尝试在将 val 传递给 useState 时删除 [] 括号。 The implication I'm getting of the warning is that its expecting an array, but instead it got an array of arrays when [val] was passed.
我收到警告的含义是它期待一个数组,但当 [val] 被传递时,它得到了一个数组数组。
In my case, I did not convert the string to numeric value.就我而言,我没有将字符串转换为数值。 The property value expects either a numeric value or an array of numbers.
属性值需要一个数值或一个数字数组。 Passing value as string, for example "23" instead of 23, can cause this warning.
将值作为字符串传递,例如“23”而不是 23,可能会导致此警告。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.