Reactjs 使用typescript:Property';数据';类型上不存在
我有一个毫无意义的错误,我正在用钩子键入我的状态值,但他说错误的类型不同 已尝试使用空数组,甚至使用一些数据的数组,但始终错误相同Reactjs 使用typescript:Property';数据';类型上不存在,reactjs,typescript,react-hooks,Reactjs,Typescript,React Hooks,我有一个毫无意义的错误,我正在用钩子键入我的状态值,但他说错误的类型不同 已尝试使用空数组,甚至使用一些数据的数组,但始终错误相同 import React, { useState } from 'react'; import { Row, Col } from 'config/styles'; import Bed from './Bed'; interface DataTypes { date: string; value: number; } function Beds():
import React, { useState } from 'react';
import { Row, Col } from 'config/styles';
import Bed from './Bed';
interface DataTypes {
date: string;
value: number;
}
function Beds(): JSX.Element {
const { data, setData } = useState<DataTypes[]>([]);
return (
<>
<Row>
{data.map((d, i) => (
<Col key={i} sm={16.666} lg={10}>
<Bed {...d} />
</Col>
))}
</Row>
</>
);
}
export default Beds;
import React,{useState}来自“React”;
从'config/styles'导入{Row,Col};
从“./床”导入床;
接口数据类型{
日期:字符串;
值:数字;
}
函数Beds():JSX.Element{
const{data,setData}=useState([]);
返回(
{data.map((d,i)=>(
))}
);
}
导出默认床位;
埃罗:
TypeScript error in /Users/keven/Documents/carenet/orquestra-frontend/src/Beds/index.tsx(11,11):
Property 'data' does not exist on type '[DataTypes[], Dispatch<SetStateAction<DataTypes[]>>]'
/Users/keven/Documents/carenet/orquestra frontend/src/Beds/index.tsx中的类型脚本错误(11,11):
类型“[DataTypes[],Dispatch]”上不存在属性“data”
它应该是一个数组,而不是一个对象:
const [data, setData] = useState<DataTypes[]>([]);
const[data,setData]=useState([]);
您在错误消息中有以下指示:
type '[DataTypes[], Dispatch<SetStateAction<DataTypes[]>>]'
type'[DataTypes[],Dispatch]'
无论类型如何,错误总是相同的。类型“[],Dispatch]”上不存在属性“data”。更改括号:const[data,setData]=…
Ooooomg:(哈哈,谢谢,抱歉!