Use SVGs in React … convert SCG file to jsx?












0















so I am relativly new to both reactJS and SVG files.



As fas a I have researched it all SVG taggs are now fully supported by react so I want to to the following:



class Example extends Component {
render() {
return(
<svg className="search__icon">
<use xlinkHref="../../public/img/sprite.svg#icon-paper-plane" />
</svg>
)
}
}


My SVG sprite sheet looks like this:



<svg aria-hidden="true" style="position: absolute; width: 0; height: 0; overflow: hidden" version="1.1">
<defs>
<symbol id="icon-paper-plane" viewBox="0 0 20 20">
<title>paper-plane</title>
<path d="M18.64 2.634c-0.344 0.121-17.321 6.104-17.656 6.222-0.284 0.1-0.347 0.345-0.010 0.479 0.401 0.161 3.796 1.521 3.796 1.521v0l2.25 0.901c0 0 10.838-7.958 10.984-8.066 0.148-0.108 0.318 0.095 0.211 0.211s-7.871 8.513-7.871 8.513v0.002l-0.452 0.503 0.599 0.322c0 0 4.65 2.504 4.982 2.682 0.291 0.156 0.668 0.027 0.752-0.334 0.099-0.426 2.845-12.261 2.906-12.525 0.079-0.343-0.148-0.552-0.491-0.431zM7 17.162c0 0.246 0.139 0.315 0.331 0.141 0.251-0.229 2.85-2.561 2.85-2.561l-3.181-1.644v4.064z"></path>
</symbol>
</defs>
</svg>


I have no SVG loader of anything installed but I still don't quite get why it doesn't work? I am using create-react-app? Can someone enlighten me? Do I have to convert the svg to to JSX attributes meaning erase the colons and use camelToe notation? Do I have to import the svg somehow to my component?










share|improve this question



























    0















    so I am relativly new to both reactJS and SVG files.



    As fas a I have researched it all SVG taggs are now fully supported by react so I want to to the following:



    class Example extends Component {
    render() {
    return(
    <svg className="search__icon">
    <use xlinkHref="../../public/img/sprite.svg#icon-paper-plane" />
    </svg>
    )
    }
    }


    My SVG sprite sheet looks like this:



    <svg aria-hidden="true" style="position: absolute; width: 0; height: 0; overflow: hidden" version="1.1">
    <defs>
    <symbol id="icon-paper-plane" viewBox="0 0 20 20">
    <title>paper-plane</title>
    <path d="M18.64 2.634c-0.344 0.121-17.321 6.104-17.656 6.222-0.284 0.1-0.347 0.345-0.010 0.479 0.401 0.161 3.796 1.521 3.796 1.521v0l2.25 0.901c0 0 10.838-7.958 10.984-8.066 0.148-0.108 0.318 0.095 0.211 0.211s-7.871 8.513-7.871 8.513v0.002l-0.452 0.503 0.599 0.322c0 0 4.65 2.504 4.982 2.682 0.291 0.156 0.668 0.027 0.752-0.334 0.099-0.426 2.845-12.261 2.906-12.525 0.079-0.343-0.148-0.552-0.491-0.431zM7 17.162c0 0.246 0.139 0.315 0.331 0.141 0.251-0.229 2.85-2.561 2.85-2.561l-3.181-1.644v4.064z"></path>
    </symbol>
    </defs>
    </svg>


    I have no SVG loader of anything installed but I still don't quite get why it doesn't work? I am using create-react-app? Can someone enlighten me? Do I have to convert the svg to to JSX attributes meaning erase the colons and use camelToe notation? Do I have to import the svg somehow to my component?










    share|improve this question

























      0












      0








      0








      so I am relativly new to both reactJS and SVG files.



      As fas a I have researched it all SVG taggs are now fully supported by react so I want to to the following:



      class Example extends Component {
      render() {
      return(
      <svg className="search__icon">
      <use xlinkHref="../../public/img/sprite.svg#icon-paper-plane" />
      </svg>
      )
      }
      }


      My SVG sprite sheet looks like this:



      <svg aria-hidden="true" style="position: absolute; width: 0; height: 0; overflow: hidden" version="1.1">
      <defs>
      <symbol id="icon-paper-plane" viewBox="0 0 20 20">
      <title>paper-plane</title>
      <path d="M18.64 2.634c-0.344 0.121-17.321 6.104-17.656 6.222-0.284 0.1-0.347 0.345-0.010 0.479 0.401 0.161 3.796 1.521 3.796 1.521v0l2.25 0.901c0 0 10.838-7.958 10.984-8.066 0.148-0.108 0.318 0.095 0.211 0.211s-7.871 8.513-7.871 8.513v0.002l-0.452 0.503 0.599 0.322c0 0 4.65 2.504 4.982 2.682 0.291 0.156 0.668 0.027 0.752-0.334 0.099-0.426 2.845-12.261 2.906-12.525 0.079-0.343-0.148-0.552-0.491-0.431zM7 17.162c0 0.246 0.139 0.315 0.331 0.141 0.251-0.229 2.85-2.561 2.85-2.561l-3.181-1.644v4.064z"></path>
      </symbol>
      </defs>
      </svg>


      I have no SVG loader of anything installed but I still don't quite get why it doesn't work? I am using create-react-app? Can someone enlighten me? Do I have to convert the svg to to JSX attributes meaning erase the colons and use camelToe notation? Do I have to import the svg somehow to my component?










      share|improve this question














      so I am relativly new to both reactJS and SVG files.



      As fas a I have researched it all SVG taggs are now fully supported by react so I want to to the following:



      class Example extends Component {
      render() {
      return(
      <svg className="search__icon">
      <use xlinkHref="../../public/img/sprite.svg#icon-paper-plane" />
      </svg>
      )
      }
      }


      My SVG sprite sheet looks like this:



      <svg aria-hidden="true" style="position: absolute; width: 0; height: 0; overflow: hidden" version="1.1">
      <defs>
      <symbol id="icon-paper-plane" viewBox="0 0 20 20">
      <title>paper-plane</title>
      <path d="M18.64 2.634c-0.344 0.121-17.321 6.104-17.656 6.222-0.284 0.1-0.347 0.345-0.010 0.479 0.401 0.161 3.796 1.521 3.796 1.521v0l2.25 0.901c0 0 10.838-7.958 10.984-8.066 0.148-0.108 0.318 0.095 0.211 0.211s-7.871 8.513-7.871 8.513v0.002l-0.452 0.503 0.599 0.322c0 0 4.65 2.504 4.982 2.682 0.291 0.156 0.668 0.027 0.752-0.334 0.099-0.426 2.845-12.261 2.906-12.525 0.079-0.343-0.148-0.552-0.491-0.431zM7 17.162c0 0.246 0.139 0.315 0.331 0.141 0.251-0.229 2.85-2.561 2.85-2.561l-3.181-1.644v4.064z"></path>
      </symbol>
      </defs>
      </svg>


      I have no SVG loader of anything installed but I still don't quite get why it doesn't work? I am using create-react-app? Can someone enlighten me? Do I have to convert the svg to to JSX attributes meaning erase the colons and use camelToe notation? Do I have to import the svg somehow to my component?







      reactjs svg






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 19:09









      barbaBlancobarbaBlanco

      134




      134
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53307193%2fuse-svgs-in-react-convert-scg-file-to-jsx%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53307193%2fuse-svgs-in-react-convert-scg-file-to-jsx%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Xamarin.iOS Cant Deploy on Iphone

          Glorious Revolution

          Dulmage-Mendelsohn matrix decomposition in Python