我有一个数组,数组中的每个元素都可以是cars ICar[]的数组,我在向列表中添加一个项时遇到了问题
const [carList, setCarList] = React.useState<[ICar[]]>([[]]);
在正常设置状态时,如果它是一个对象数组,我将执行以下操作
setCarList(initialList => [...initialList, JSON.parse(JSON.stringify(car))]); // this works when its just an array of ICar
但是当我把它做成[ICar[]]的时候,我就有问题
因此,我有如下的反应状态
[ state, setState] = useState(new Set([1,2,3]))
我想要不断地向集合中添加一组元素,我如何做到这一点?它对数组很简单,只需使用setState(prev=>[...prev,...newElem])就可以完成,但是如何在一组中完成。
const newElems = new Set([4,5,6]) //These are new Elements that need to be appended
setState(prev=>new Set([..prev,...newElems])) //This c
我想根据数组a的值重新呈现UI,如下所示:
const [a, setA] = useState([<sample_data>];
...
function update(newValue) {
// use push method to append the new element into a
a.push(newValue);
setA(a);
// use concat to create new array that includes a & new element
setA([].concat(a,[newValue]);
}
如
我犯了这个错误。我不知道如何解决,我在互联网上没有看到合适的解决方案。我刚开始打字,所以我不知道怎么解决这个问题。最初,该项目是在js上进行的,因此它将使用ts迁移转移到ts。现在我正在纠正由于转移引起的错误。
错误码:
TS2769:没有与此调用匹配的重载。--
Overload 1 of 2, '(props: BrowserRouterProps | Readonly<BrowserRouterProps>): BrowserRouter', gave the following error.
Type '{ children: (stri