nathanjhood / ts-esbuild-react

A React starter project template with esbuild-scripts.
https://nathanjhood.github.io/ts-esbuild-react/
Other
0 stars 0 forks source link

casting '.svg' file extensions to React components (the React Native way) #19

Closed nathanjhood closed 3 weeks ago

nathanjhood commented 2 months ago

Add a React component export to the '*.svg' module declaration:

declare module "*.svg" {
  import * as React from "react";

  export const ReactComponent: React.FunctionComponent<
    React.SVGProps<SVGSVGElement> & { title?: string }
  >;

  const src: string;
  export default src;
}

Import the React component part of the module:

import { ReactComponent as Logo} from './logo.svg';
import './App.css';

function App() {
  return (
    <div className="App">
      <Logo />
    </div>
  );
}
export default App;

I wonder if we can coerce HTML files in the same way :) (reference #16 )

nathanjhood commented 3 weeks ago

Solved ages ago...