Create React Svg from an array of elements
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
Given an array representing the tags of an svg ,
(6) ["<svg id="Ebene_1" style={{"enableBackground":"new …rg/2000/svg" x="0px" y="0px" xmlSpace="preserve">", "<g>", "<polygon style={{"fillRule":"evenodd","clipRule":"…9,12 24,12 24,15 19,15 19,18 14,18 14,21 "/>", "<path d="M3.4,20.5c-0.1,0-0.3-0.1-0.4-0.2c-0.1-0.2…,0.4h-3.3L3.7,20.4C3.6,20.5,3.5,20.5,3.4,20.5z"/>", "</g>", "</svg>"]
0: "<svg id="Ebene_1" style={{"enableBackground":"new 0 0 32 32"}} version="1.1" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" xmlSpace="preserve">"
1: "<g>"
2: "<polygon style={{"fillRule":"evenodd","clipRule":"evenodd"}} points="9,21 9,24 4,24 4,27 8.5,27 9.4,27 13.7,27 18.8,27 23.9,27 29,27
29,12 24,12 24,15 19,15 19,18 14,18 14,21 "/>"
3: "<path d="M3.4,20.5c-0.1,0-0.3-0.1-0.4-0.2c-0.1-0.2-0.1-0.5,0.1-0.6L24.5,5.2c0.1,0,0.2-0.1,0.2-0.1h3.4c0.2,0,0.4,0.2,0.4,0.4
c0,0.2-0.2,0.4-0.4,0.4h-3.3L3.7,20.4C3.6,20.5,3.5,20.5,3.4,20.5z"/>"
4: "</g>"
5: "</svg>"
length: 6
__proto__: Array(0)
how do I go about recreating the svg in react. It has to be done on the fly as the image given to me is a users choice, and as such I cannot just replicate each array item in react and pass in the props.
javascript reactjs svg
add a comment |
Given an array representing the tags of an svg ,
(6) ["<svg id="Ebene_1" style={{"enableBackground":"new …rg/2000/svg" x="0px" y="0px" xmlSpace="preserve">", "<g>", "<polygon style={{"fillRule":"evenodd","clipRule":"…9,12 24,12 24,15 19,15 19,18 14,18 14,21 "/>", "<path d="M3.4,20.5c-0.1,0-0.3-0.1-0.4-0.2c-0.1-0.2…,0.4h-3.3L3.7,20.4C3.6,20.5,3.5,20.5,3.4,20.5z"/>", "</g>", "</svg>"]
0: "<svg id="Ebene_1" style={{"enableBackground":"new 0 0 32 32"}} version="1.1" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" xmlSpace="preserve">"
1: "<g>"
2: "<polygon style={{"fillRule":"evenodd","clipRule":"evenodd"}} points="9,21 9,24 4,24 4,27 8.5,27 9.4,27 13.7,27 18.8,27 23.9,27 29,27
29,12 24,12 24,15 19,15 19,18 14,18 14,21 "/>"
3: "<path d="M3.4,20.5c-0.1,0-0.3-0.1-0.4-0.2c-0.1-0.2-0.1-0.5,0.1-0.6L24.5,5.2c0.1,0,0.2-0.1,0.2-0.1h3.4c0.2,0,0.4,0.2,0.4,0.4
c0,0.2-0.2,0.4-0.4,0.4h-3.3L3.7,20.4C3.6,20.5,3.5,20.5,3.4,20.5z"/>"
4: "</g>"
5: "</svg>"
length: 6
__proto__: Array(0)
how do I go about recreating the svg in react. It has to be done on the fly as the image given to me is a users choice, and as such I cannot just replicate each array item in react and pass in the props.
javascript reactjs svg
add a comment |
Given an array representing the tags of an svg ,
(6) ["<svg id="Ebene_1" style={{"enableBackground":"new …rg/2000/svg" x="0px" y="0px" xmlSpace="preserve">", "<g>", "<polygon style={{"fillRule":"evenodd","clipRule":"…9,12 24,12 24,15 19,15 19,18 14,18 14,21 "/>", "<path d="M3.4,20.5c-0.1,0-0.3-0.1-0.4-0.2c-0.1-0.2…,0.4h-3.3L3.7,20.4C3.6,20.5,3.5,20.5,3.4,20.5z"/>", "</g>", "</svg>"]
0: "<svg id="Ebene_1" style={{"enableBackground":"new 0 0 32 32"}} version="1.1" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" xmlSpace="preserve">"
1: "<g>"
2: "<polygon style={{"fillRule":"evenodd","clipRule":"evenodd"}} points="9,21 9,24 4,24 4,27 8.5,27 9.4,27 13.7,27 18.8,27 23.9,27 29,27
29,12 24,12 24,15 19,15 19,18 14,18 14,21 "/>"
3: "<path d="M3.4,20.5c-0.1,0-0.3-0.1-0.4-0.2c-0.1-0.2-0.1-0.5,0.1-0.6L24.5,5.2c0.1,0,0.2-0.1,0.2-0.1h3.4c0.2,0,0.4,0.2,0.4,0.4
c0,0.2-0.2,0.4-0.4,0.4h-3.3L3.7,20.4C3.6,20.5,3.5,20.5,3.4,20.5z"/>"
4: "</g>"
5: "</svg>"
length: 6
__proto__: Array(0)
how do I go about recreating the svg in react. It has to be done on the fly as the image given to me is a users choice, and as such I cannot just replicate each array item in react and pass in the props.
javascript reactjs svg
Given an array representing the tags of an svg ,
(6) ["<svg id="Ebene_1" style={{"enableBackground":"new …rg/2000/svg" x="0px" y="0px" xmlSpace="preserve">", "<g>", "<polygon style={{"fillRule":"evenodd","clipRule":"…9,12 24,12 24,15 19,15 19,18 14,18 14,21 "/>", "<path d="M3.4,20.5c-0.1,0-0.3-0.1-0.4-0.2c-0.1-0.2…,0.4h-3.3L3.7,20.4C3.6,20.5,3.5,20.5,3.4,20.5z"/>", "</g>", "</svg>"]
0: "<svg id="Ebene_1" style={{"enableBackground":"new 0 0 32 32"}} version="1.1" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" xmlSpace="preserve">"
1: "<g>"
2: "<polygon style={{"fillRule":"evenodd","clipRule":"evenodd"}} points="9,21 9,24 4,24 4,27 8.5,27 9.4,27 13.7,27 18.8,27 23.9,27 29,27
29,12 24,12 24,15 19,15 19,18 14,18 14,21 "/>"
3: "<path d="M3.4,20.5c-0.1,0-0.3-0.1-0.4-0.2c-0.1-0.2-0.1-0.5,0.1-0.6L24.5,5.2c0.1,0,0.2-0.1,0.2-0.1h3.4c0.2,0,0.4,0.2,0.4,0.4
c0,0.2-0.2,0.4-0.4,0.4h-3.3L3.7,20.4C3.6,20.5,3.5,20.5,3.4,20.5z"/>"
4: "</g>"
5: "</svg>"
length: 6
__proto__: Array(0)
how do I go about recreating the svg in react. It has to be done on the fly as the image given to me is a users choice, and as such I cannot just replicate each array item in react and pass in the props.
(6) ["<svg id="Ebene_1" style={{"enableBackground":"new …rg/2000/svg" x="0px" y="0px" xmlSpace="preserve">", "<g>", "<polygon style={{"fillRule":"evenodd","clipRule":"…9,12 24,12 24,15 19,15 19,18 14,18 14,21 "/>", "<path d="M3.4,20.5c-0.1,0-0.3-0.1-0.4-0.2c-0.1-0.2…,0.4h-3.3L3.7,20.4C3.6,20.5,3.5,20.5,3.4,20.5z"/>", "</g>", "</svg>"]
0: "<svg id="Ebene_1" style={{"enableBackground":"new 0 0 32 32"}} version="1.1" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" xmlSpace="preserve">"
1: "<g>"
2: "<polygon style={{"fillRule":"evenodd","clipRule":"evenodd"}} points="9,21 9,24 4,24 4,27 8.5,27 9.4,27 13.7,27 18.8,27 23.9,27 29,27
29,12 24,12 24,15 19,15 19,18 14,18 14,21 "/>"
3: "<path d="M3.4,20.5c-0.1,0-0.3-0.1-0.4-0.2c-0.1-0.2-0.1-0.5,0.1-0.6L24.5,5.2c0.1,0,0.2-0.1,0.2-0.1h3.4c0.2,0,0.4,0.2,0.4,0.4
c0,0.2-0.2,0.4-0.4,0.4h-3.3L3.7,20.4C3.6,20.5,3.5,20.5,3.4,20.5z"/>"
4: "</g>"
5: "</svg>"
length: 6
__proto__: Array(0)
(6) ["<svg id="Ebene_1" style={{"enableBackground":"new …rg/2000/svg" x="0px" y="0px" xmlSpace="preserve">", "<g>", "<polygon style={{"fillRule":"evenodd","clipRule":"…9,12 24,12 24,15 19,15 19,18 14,18 14,21 "/>", "<path d="M3.4,20.5c-0.1,0-0.3-0.1-0.4-0.2c-0.1-0.2…,0.4h-3.3L3.7,20.4C3.6,20.5,3.5,20.5,3.4,20.5z"/>", "</g>", "</svg>"]
0: "<svg id="Ebene_1" style={{"enableBackground":"new 0 0 32 32"}} version="1.1" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg" x="0px" y="0px" xmlSpace="preserve">"
1: "<g>"
2: "<polygon style={{"fillRule":"evenodd","clipRule":"evenodd"}} points="9,21 9,24 4,24 4,27 8.5,27 9.4,27 13.7,27 18.8,27 23.9,27 29,27
29,12 24,12 24,15 19,15 19,18 14,18 14,21 "/>"
3: "<path d="M3.4,20.5c-0.1,0-0.3-0.1-0.4-0.2c-0.1-0.2-0.1-0.5,0.1-0.6L24.5,5.2c0.1,0,0.2-0.1,0.2-0.1h3.4c0.2,0,0.4,0.2,0.4,0.4
c0,0.2-0.2,0.4-0.4,0.4h-3.3L3.7,20.4C3.6,20.5,3.5,20.5,3.4,20.5z"/>"
4: "</g>"
5: "</svg>"
length: 6
__proto__: Array(0)
javascript reactjs svg
javascript reactjs svg
asked Nov 23 '18 at 20:33
FluxFlux
155
155
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
you can use svg-inline-loader with webpack.
Add the loader in webpack config
{
test: /.svg$/,
loader: 'svg-inline-loader',
},
Install svg-inline-react from npm
You can import a svg like this:
const icon = require('svg/icon.svg');
And you can use like this:
import InlineSVG from 'svg-inline-react';
<InlineSVG src={require("svg-inline-loader!icon.svg")} />
Thank you but I don't have the svg saved , it is fetched with the response being an array, as shown, I need a way of recreating the elements on the fly.
– Flux
Nov 24 '18 at 10:01
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452669%2fcreate-react-svg-from-an-array-of-elements%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
you can use svg-inline-loader with webpack.
Add the loader in webpack config
{
test: /.svg$/,
loader: 'svg-inline-loader',
},
Install svg-inline-react from npm
You can import a svg like this:
const icon = require('svg/icon.svg');
And you can use like this:
import InlineSVG from 'svg-inline-react';
<InlineSVG src={require("svg-inline-loader!icon.svg")} />
Thank you but I don't have the svg saved , it is fetched with the response being an array, as shown, I need a way of recreating the elements on the fly.
– Flux
Nov 24 '18 at 10:01
add a comment |
you can use svg-inline-loader with webpack.
Add the loader in webpack config
{
test: /.svg$/,
loader: 'svg-inline-loader',
},
Install svg-inline-react from npm
You can import a svg like this:
const icon = require('svg/icon.svg');
And you can use like this:
import InlineSVG from 'svg-inline-react';
<InlineSVG src={require("svg-inline-loader!icon.svg")} />
Thank you but I don't have the svg saved , it is fetched with the response being an array, as shown, I need a way of recreating the elements on the fly.
– Flux
Nov 24 '18 at 10:01
add a comment |
you can use svg-inline-loader with webpack.
Add the loader in webpack config
{
test: /.svg$/,
loader: 'svg-inline-loader',
},
Install svg-inline-react from npm
You can import a svg like this:
const icon = require('svg/icon.svg');
And you can use like this:
import InlineSVG from 'svg-inline-react';
<InlineSVG src={require("svg-inline-loader!icon.svg")} />
you can use svg-inline-loader with webpack.
Add the loader in webpack config
{
test: /.svg$/,
loader: 'svg-inline-loader',
},
Install svg-inline-react from npm
You can import a svg like this:
const icon = require('svg/icon.svg');
And you can use like this:
import InlineSVG from 'svg-inline-react';
<InlineSVG src={require("svg-inline-loader!icon.svg")} />
answered Nov 24 '18 at 2:09
Fernando ColomFernando Colom
1813
1813
Thank you but I don't have the svg saved , it is fetched with the response being an array, as shown, I need a way of recreating the elements on the fly.
– Flux
Nov 24 '18 at 10:01
add a comment |
Thank you but I don't have the svg saved , it is fetched with the response being an array, as shown, I need a way of recreating the elements on the fly.
– Flux
Nov 24 '18 at 10:01
Thank you but I don't have the svg saved , it is fetched with the response being an array, as shown, I need a way of recreating the elements on the fly.
– Flux
Nov 24 '18 at 10:01
Thank you but I don't have the svg saved , it is fetched with the response being an array, as shown, I need a way of recreating the elements on the fly.
– Flux
Nov 24 '18 at 10:01
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452669%2fcreate-react-svg-from-an-array-of-elements%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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