How To use in React Native #472
-
|
I am trying to use in react native. but, I can use it by manually copy paste SVG. I want to use it dynamically by using Import in React Native. Is it available for React Native? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
For React Native I would not use The base import { SvgXml } from 'react-native-svg';
import github from 'thesvg/github';
export function GithubIcon() {
return <SvgXml xml={github.svg} width={24} height={24} />;
}Install both packages: npm install thesvg react-native-svgIf by dynamic import you mean choosing an icon by name at runtime, Metro still needs to know possible imports at build time. A small map is usually the safest option: const icons = {
github: () => import('thesvg/github'),
figma: () => import('thesvg/figma'),
};For truly arbitrary icon names, use the CDN/API URL, fetch the SVG XML, and pass it to |
Beta Was this translation helpful? Give feedback.
For React Native I would not use
@thesvg/reactdirectly, since that package is for web React components.The base
thesvgpackage gives you raw SVG strings, so in React Native you can render them withreact-native-svg:Install both packages:
If by dynamic import you mean choosing an icon by name at runtime, Metro still needs to know possible imports at build time. A small map is usually the safest option: