How to use this API in React? #155
-
How can I use the response svg in React as the response returned is in HTML and React needs JSX. I tried few tricks but didn't able to use it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Version 5.x
Version 4.xThe safest way is to use it with const avatar = createAvatar(style, {
dataUri: true,
})
<img src={avatar} /> CodeSandbox example: Another solution without img element but with real SVG element can be achieved with the lib const avatar = createAvatar(style, {
dataUri: true
});
return <Svg src={avatar} alt="avatar" />; CodeSandbox example: But also |
Beta Was this translation helpful? Give feedback.
Version 5.x
Version 4.x
The safest way is to use it with
dataUri
option.CodeSandbox example:
https://codesandbox.io/s/pensive-herschel-8ybqw?file=/src/App.js
Another solution without img element but with real SVG element can be achieved with the lib
react-inlinesvg
.CodeSandbox example:
https://codesandbox.io/s/discussions-155-2-wz7lm?file=/src/App.js:198-363
But also
dangerouslySetInnerHTML
s…