Giter VIP home page Giter VIP logo

Comments (5)

oleastre avatar oleastre commented on July 28, 2024 20

Just hit by the same issue today, I searched a bit how to solve this.
I am only using @rescripts/rescript-use-babel-config with a custom .babelrc file.
To solve the problem, I had to add this plugin in my .babelrc config:

    "plugins": [
        ["babel-plugin-named-asset-import", {
          "loaderMap": {
            "svg": {
              "ReactComponent": "@svgr/webpack?-svgo,+ref![path]"
            }
          }
        }]
    ]

This sould probably be added somewhere in the use-babel-config documentation.

And note also that the correct syntax to load svg is

import { ReactComponent as Logo } from './logo.svg';
class App extends Component {
  render() {
    return (
          <Logo width="400px" height="400px" />
    );
  }
}

from rescripts.

harrysolovay avatar harrysolovay commented on July 28, 2024

Hi @hckhanh –– I don't believe this to be an issue with Rescripts. Still, I'll try to offer some support.

This kind of import seems a little strange:

import { ReactComponent as DeleteIcon } from './delete.svg';

There's no exported "ReactComponent" from an svg file. Maybe replace with the following:

import DeleteIcon from './delete.svg';

I hope this is helpful (there's a change you'll need to include an SVG loader such as airbnb's). Although I'm pretty sure SVG imports are supported as of CRA 2.0+. Keep me posted :)

from rescripts.

hckhanh avatar hckhanh commented on July 28, 2024

@harrysolovay I think this is a new feature is supported by CRA. When I do by this way, it will convert data in svg file to a React component like this:

image

You're right, it's strange when I use it in the first time but I think this one is really good, like the same way Github inserts their svg file.

It runs perfectly when use react-scripts. You can try react-scripts start to test it 👍

Additionally, I can add event such as onClick as a native component like div

from rescripts.

harrysolovay avatar harrysolovay commented on July 28, 2024

@hckhanh can you send me a link to the example so I can debug?

from rescripts.

harrysolovay avatar harrysolovay commented on July 28, 2024

@hckhanh hopefully you managed to find the problem. Gonna close this issue. Feel free to reopen if necessary.

from rescripts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.