Reputation: 1073
I am converting a React component into Typescript (*.ts) from JS. It is giving the error below "Type expected". How would I fix this?
const SisenseDashboard = () => {
const sisenseRef = React.useRef(null);
return (
<>
<Box
display="flex"
flexDirection="column"
alignItems="center"
marginBottom={2}
>
<h2>In-App Reporting</h2>
</Box>
<Box
ref={sisenseRef}
id="sisense-container"
className="sisense-demo"
></Box>
</>
);
};
Upvotes: 8
Views: 5884
Reputation: 45825
Make sure your component file extension is .tsx
and not .ts
. This should resolve your issue. Addinonnaly, you could tell TypeScript that your function is a React Functional Component, for example, with the help of the FC
type from React:
import {FC} from "react";
const SisenseDashboard : FC = () => {
const sisenseRef = React.useRef(null);
return (
<>
<Box
display="flex"
flexDirection="column"
alignItems="center"
marginBottom={2}
>
<h2>In-App Reporting</h2>
</Box>
<Box
ref={sisenseRef}
id="sisense-container"
className="sisense-demo"
></Box>
</>
);
};
Upvotes: 23