FortAwesome / react-native-fontawesome

Official React Native component for Font Awesome 5
MIT License
328 stars 53 forks source link

Dynamically Load Font Awesome Icon From API #165

Open cblaze22 opened 1 year ago

cblaze22 commented 1 year ago

If we want to dynamically build a menu with icons through a web api, is it possible to reference 'faMugSaucer' as a string to a component like below?


import { View } from 'react-native'
import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome'
import { faMugSaucer } from '@fortawesome/free-solid-svg-icons/faMugSaucer'

type Props = {}
export default class App extends Component<Props> {
  render() {
    return (
      <View>
        <FontAwesomeIcon icon={ faMugSaucer } />
      </View>
    )
  }
}```
Gautammer commented 4 months ago

is there any update?

Gautammer commented 4 months ago

@cblaze22 ok i solved by this:

import { FontAwesomeIcon } from '@fortawesome/react-native-fontawesome';
import { library } from "@fortawesome/fontawesome-svg-core";
import { fab } from '@fortawesome/free-brands-svg-icons';
import { far } from '@fortawesome/free-regular-svg-icons';
import { fas } from '@fortawesome/free-solid-svg-icons';

library.add(fab, far, fas);

<FontAwesomeIcon icon={'any-fa-name-string'} />