let [mapPredictionData, setMapPredictionData] = useState({
prediction_index : 0,
prediction_point : null,
prediction_point_distance : null
})
.....some other code
setMapPredictionData({
prediction_index: prev_index,
prediction_point: props.missionLocationArray[prev_index],
prediction_point_distance: get_distance_between_points(props.missionLocationArray[prev_index], currentPosition)
})
以上是我如何使用React钩子useState声明状态并遵循如何设置相同状态的方法。 但是每次我设置状态时,它通常都不会改变,并且会出现错误-
“参数类型{prediction_index:数字,precision_point_distance:数字,precision_point:*}不可分配给参数类型((prevState:{prediction_index:数字,predict_point_distance:null,precision_point:null})=> {prediction_index:数字, projection_point_distance:null,precision_point:null})| {prediction_index:数字,precision_point_distance:null,precision_point:null}“
我尝试研究解决方案,但失败了。有人知道为什么会这样吗?