我已经成功让Material UI 评级组件正常工作。但是,当我单击评级时,评级不会更新。
这是我到目前为止所拥有的。
const Product = props => {
const [rating, setRating] = useState(cumRating);
const updateRating = (newRating) => {
setRating(newRating);
console.log(rating);
}
return (
<Rating
value={rating}
precision={0.5}
max={5}
name="hover-feedback"
onChange={(event, newValue) => updateRating(newValue)}
onChangeActive={(event, newHover) => {
setHover(newHover);
}}
/>
)
Run Code Online (Sandbox Code Playgroud)
}
当我执行 console.log( rating) 时,它会打印出正确的评级,但不会更新星号 UI 组件。
然后我删除了评级中的名称属性,它起作用了。但我收到这个错误。有某种解决方法可以隐藏此错误吗?
为什么这个错误会不断出现?这个 name 属性到底有什么作用?我尝试将 readOnly 设置为 true,但我不再获得我想要的悬停效果。
Warning: Failed prop type: Material-UI: The prop `name` is required (when `readOnly` is false).
Additionally, the input name should be unique …Run Code Online (Sandbox Code Playgroud) 假设我有一个修改数据库的文件,函数应该共享一个上下文还是每个函数都有自己的上下文?
共享上下文
var (
ctx = context.Background()
)
func test1() {
res, err := Collection.InsertOne(ctx, data)
}
func test2() {
res, err := Collection.InsertOne(ctx, data)
}
Run Code Online (Sandbox Code Playgroud)
或者应该是这样的?
func test1() {
res, err := Collection.InsertOne(context.Background(), data)
}
func test2() {
res, err := Collection.InsertOne(context.Background(), data)
}
Run Code Online (Sandbox Code Playgroud)