microsoft / TypeScript-React-Starter

A starter template for TypeScript and React with a detailed README describing how to use the two together.
MIT License
11.09k stars 1.21k forks source link

Piece missing in README-CRA.md, adding svg throws error #196

Open chandelabhishek opened 6 years ago

chandelabhishek commented 6 years ago
Adding SVGs
Note: this feature is available with react-scripts@2.0.0 and higher.

One way to add SVG files was described in the section above. You can also import SVGs directly as React components. You can use either of the two approaches. In your code it would look like this:

import { ReactComponent as Logo } from './logo.svg';
const App = () => (
  <div>
    {/* Logo is an actual React component */}
    <Logo />
  </div>
);
This is handy if you don't want to load SVG as a separate file. Don't forget the curly braces in the import! The ReactComponent import name is special and tells Create React App that you want a React component that renders an SVG, rather than its filename.

Above tutorial snippet is missing but we have this in javascript version, please check this out. If I follow tutorial as mentioned in the link. It does not work. it throws following error:

Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.

Kindly help

Justyn2 commented 6 years ago

@chandelabhishek008 I believe this has more to do with react-scripts-ts in create-react-app-typescript which is what this project is created from.

bluemoehre commented 5 years ago

I ran into the same problem right now ... did I something wrong or is there a fix?