mattsmith5
mattsmith5

Reputation: 1073

React and TypeScript, getting "Type expected" error

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>
    </>
  );
};

enter image description here

Upvotes: 8

Views: 5884

Answers (1)

Youssouf Oumar
Youssouf Oumar

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

Related Questions