alernerdev
alernerdev

Reputation: 2064

how to export React component from a typescript file

I have a class that looks like this:

class ProductChecker extends React.Component { .... }

at the bottom of the file, I have:

export default graphql(getSymbolInfoQuery)(ProductChecker);

where graphql is imported from react-apollo and getSymbolInfoQuery is a gql templated string. When compiling the project, I am getting:

src/client/gui/containers/product-checker.ts(3,10): error TS2305: Module '"../components/product-checker"' has no exported member 'ProductChecker'

but when I comment out the bottom of the file line and do:

export class ProductChecker extends React.Component {

that seems to be building just fine. So it looks like the export at the bottom of the file does not "see" class/component declaration higher up, and says that its not found. Any idea how to export a React class from a typescript source file? THank you

Upvotes: 0

Views: 2178

Answers (1)

Ryan Cogswell
Ryan Cogswell

Reputation: 80986

The issue is most likely your import statement where you are using this. I suspect you have:

import {ProductChecker} from "yourfilename";

but it should be:

import ProductChecker from "yourfilename";

The first assumes a named export, the second is for a default export.

Upvotes: 2

Related Questions