-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use this lib as a react component #2
Comments
Thanks @rhacker! I don’t know React super well (I use Elm instead), but I created the following examples on CodePen:
Let me know if it works for you. |
i think there is some problem in index.html, i tried change import { identiconSvg } from "./minidenticons.min.js" into import { identicon } from "https://unpkg.com/[email protected]/minidenticons.min.js"; and it works, try it out @rhacker |
Yet another way is to extend the |
It's usually better to include SVG inside Here is a complete React component to use this concept: import { identicon } from "minidenticons"
import React, { ImgHTMLAttributes, useMemo } from "react"
interface IdentityIconProps extends Omit<ImgHTMLAttributes<HTMLImageElement>, "src"> {
username: string
saturation?: string | number
lightness?: string | number
}
const IdentityIcon: React.FC<IdentityIconProps> = ({ username, saturation, lightness, ...props }) => {
const svgText = useMemo(() => identicon(username, saturation, lightness), [username, saturation, lightness])
return <img src={`data:image/svg+xml;utf8,${encodeURIComponent(svgText)}`} alt={username} {...props} />
}
export default IdentityIcon Then it can be used like so: <IdentityIcon username="Hello world" width={300} /> |
Thanks @danyi1212! I’m actually using |
@danyi1212 I simplified your example from TS to JS and put it in the v3 docs with a link to your original comment. I also created one more CodePen for this:
|
Hi, this lib looks fantastic and fast! How do we use this as a react component?
thanks
The text was updated successfully, but these errors were encountered: