Skip to content

How to use this API in React? #155

Closed Answered by FlorianKoerner
Launchpad5682 asked this question in Q&A
Discussion options

You must be logged in to vote

Version 5.x

Version 4.x

The safest way is to use it with dataUri option.

const avatar = createAvatar(style, {
  dataUri: true,
})

<img src={avatar} />

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.

const avatar = createAvatar(style, {
  dataUri: true
});

return <Svg src={avatar} alt="avatar" />;

CodeSandbox example:
https://codesandbox.io/s/discussions-155-2-wz7lm?file=/src/App.js:198-363


But also dangerouslySetInnerHTML s…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Launchpad5682
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #154 on September 10, 2021 07:21.