How to use fontawesome in react?












1















I want use fontawesome in my react project, i read document and add fontawesome with yarn:



$ yarn add @fortawesome/fontawesome-svg-core
$ yarn add @fortawesome/free-solid-svg-icons
$ yarn add @fortawesome/react-fontawesome


and create a component like as below:



import React, { Component } from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

class Todo extends Component {
render() {
return (
<div>
font: <FontAwesomeIcon icon="coffee" />

</div>
);
}
}

export default Todo;


But don't show icon, how fix this?










share|improve this question























  • You could have a look at this library too. react-icons.netlify.com/#

    – dmraptis
    Jan 18 at 16:17
















1















I want use fontawesome in my react project, i read document and add fontawesome with yarn:



$ yarn add @fortawesome/fontawesome-svg-core
$ yarn add @fortawesome/free-solid-svg-icons
$ yarn add @fortawesome/react-fontawesome


and create a component like as below:



import React, { Component } from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

class Todo extends Component {
render() {
return (
<div>
font: <FontAwesomeIcon icon="coffee" />

</div>
);
}
}

export default Todo;


But don't show icon, how fix this?










share|improve this question























  • You could have a look at this library too. react-icons.netlify.com/#

    – dmraptis
    Jan 18 at 16:17














1












1








1








I want use fontawesome in my react project, i read document and add fontawesome with yarn:



$ yarn add @fortawesome/fontawesome-svg-core
$ yarn add @fortawesome/free-solid-svg-icons
$ yarn add @fortawesome/react-fontawesome


and create a component like as below:



import React, { Component } from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

class Todo extends Component {
render() {
return (
<div>
font: <FontAwesomeIcon icon="coffee" />

</div>
);
}
}

export default Todo;


But don't show icon, how fix this?










share|improve this question














I want use fontawesome in my react project, i read document and add fontawesome with yarn:



$ yarn add @fortawesome/fontawesome-svg-core
$ yarn add @fortawesome/free-solid-svg-icons
$ yarn add @fortawesome/react-fontawesome


and create a component like as below:



import React, { Component } from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

class Todo extends Component {
render() {
return (
<div>
font: <FontAwesomeIcon icon="coffee" />

</div>
);
}
}

export default Todo;


But don't show icon, how fix this?







javascript reactjs font-awesome






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 18 at 16:08









Masoud92mMasoud92m

1299




1299













  • You could have a look at this library too. react-icons.netlify.com/#

    – dmraptis
    Jan 18 at 16:17



















  • You could have a look at this library too. react-icons.netlify.com/#

    – dmraptis
    Jan 18 at 16:17

















You could have a look at this library too. react-icons.netlify.com/#

– dmraptis
Jan 18 at 16:17





You could have a look at this library too. react-icons.netlify.com/#

– dmraptis
Jan 18 at 16:17












4 Answers
4






active

oldest

votes


















1














You seem to be missing some imports.



import { library } from '@fortawesome/fontawesome-svg-core'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faIgloo } from '@fortawesome/free-solid-svg-icons'

library.add(faIgloo)


https://fontawesome.com/how-to-use/on-the-web/using-with/react






share|improve this answer































    1














    If you want to reference the icon by its name you have to declare a library:



    import ReactDOM from 'react-dom'
    import { library } from '@fortawesome/fontawesome-svg-core'
    import { fab } from '@fortawesome/free-brands-svg-icons'
    import { faCheckSquare, faCoffee } from '@fortawesome/free-solid-svg-icons'

    library.add(fab, faCheckSquare, faCoffee)


    Then use it like this:



    import React from 'react'
    import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'

    export const Beverage = () => (
    <div>
    <FontAwesomeIcon icon="check-square" />
    Favorite beverage: <FontAwesomeIcon icon="coffee" />
    </div>
    )


    Otherwise, you can use explicit imports:



    import ReactDOM from 'react-dom'
    import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
    import { faCoffee } from '@fortawesome/free-solid-svg-icons'

    const element = <FontAwesomeIcon icon={faCoffee} />

    ReactDOM.render(element, document.body)


    All this bits of details are explained here. The above examples are from there.






    share|improve this answer































      0














      It could be that you are spelling 'fortawesome' and not 'fontawesome'






      share|improve this answer
























      • Oddly, that's how it's specified in the docs. fontawesome.com/how-to-use/on-the-web/using-with/react

        – isherwood
        Jan 18 at 16:11











      • @isherwood Weird, I didn't check the docs, just glanced over his code. I wonder why they did that

        – remoo
        Jan 18 at 16:12











      • IIRC fortawesome used to be their domain. Maybe before they got the big $ from the kickstarter

        – engineerDave
        Jan 18 at 16:23



















      -1














      Firstly you should use npm to install the react package




      npm i -g yarn



      yarn add react-native-fontawesome




      After this you must import the data to start using in your project



      import FontAwesome, { Icons } from 'react-native-fontawesome';

      ...
      render() {
      return (
      <View>
      <Text style={{margin: 10, fontSize: 15, textAlign: 'left'}}>
      <FontAwesome>{Icons.chevronLeft}</FontAwesome>
      Text
      </Text>
      </View>
      );
      },


      if you want a more complete tutorial you can access the tutorial clicking here






      share|improve this answer























        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54257590%2fhow-to-use-fontawesome-in-react%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        1














        You seem to be missing some imports.



        import { library } from '@fortawesome/fontawesome-svg-core'
        import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
        import { faIgloo } from '@fortawesome/free-solid-svg-icons'

        library.add(faIgloo)


        https://fontawesome.com/how-to-use/on-the-web/using-with/react






        share|improve this answer




























          1














          You seem to be missing some imports.



          import { library } from '@fortawesome/fontawesome-svg-core'
          import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
          import { faIgloo } from '@fortawesome/free-solid-svg-icons'

          library.add(faIgloo)


          https://fontawesome.com/how-to-use/on-the-web/using-with/react






          share|improve this answer


























            1












            1








            1







            You seem to be missing some imports.



            import { library } from '@fortawesome/fontawesome-svg-core'
            import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
            import { faIgloo } from '@fortawesome/free-solid-svg-icons'

            library.add(faIgloo)


            https://fontawesome.com/how-to-use/on-the-web/using-with/react






            share|improve this answer













            You seem to be missing some imports.



            import { library } from '@fortawesome/fontawesome-svg-core'
            import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
            import { faIgloo } from '@fortawesome/free-solid-svg-icons'

            library.add(faIgloo)


            https://fontawesome.com/how-to-use/on-the-web/using-with/react







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 18 at 16:15









            isherwoodisherwood

            36.8k1082111




            36.8k1082111

























                1














                If you want to reference the icon by its name you have to declare a library:



                import ReactDOM from 'react-dom'
                import { library } from '@fortawesome/fontawesome-svg-core'
                import { fab } from '@fortawesome/free-brands-svg-icons'
                import { faCheckSquare, faCoffee } from '@fortawesome/free-solid-svg-icons'

                library.add(fab, faCheckSquare, faCoffee)


                Then use it like this:



                import React from 'react'
                import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'

                export const Beverage = () => (
                <div>
                <FontAwesomeIcon icon="check-square" />
                Favorite beverage: <FontAwesomeIcon icon="coffee" />
                </div>
                )


                Otherwise, you can use explicit imports:



                import ReactDOM from 'react-dom'
                import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
                import { faCoffee } from '@fortawesome/free-solid-svg-icons'

                const element = <FontAwesomeIcon icon={faCoffee} />

                ReactDOM.render(element, document.body)


                All this bits of details are explained here. The above examples are from there.






                share|improve this answer




























                  1














                  If you want to reference the icon by its name you have to declare a library:



                  import ReactDOM from 'react-dom'
                  import { library } from '@fortawesome/fontawesome-svg-core'
                  import { fab } from '@fortawesome/free-brands-svg-icons'
                  import { faCheckSquare, faCoffee } from '@fortawesome/free-solid-svg-icons'

                  library.add(fab, faCheckSquare, faCoffee)


                  Then use it like this:



                  import React from 'react'
                  import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'

                  export const Beverage = () => (
                  <div>
                  <FontAwesomeIcon icon="check-square" />
                  Favorite beverage: <FontAwesomeIcon icon="coffee" />
                  </div>
                  )


                  Otherwise, you can use explicit imports:



                  import ReactDOM from 'react-dom'
                  import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
                  import { faCoffee } from '@fortawesome/free-solid-svg-icons'

                  const element = <FontAwesomeIcon icon={faCoffee} />

                  ReactDOM.render(element, document.body)


                  All this bits of details are explained here. The above examples are from there.






                  share|improve this answer


























                    1












                    1








                    1







                    If you want to reference the icon by its name you have to declare a library:



                    import ReactDOM from 'react-dom'
                    import { library } from '@fortawesome/fontawesome-svg-core'
                    import { fab } from '@fortawesome/free-brands-svg-icons'
                    import { faCheckSquare, faCoffee } from '@fortawesome/free-solid-svg-icons'

                    library.add(fab, faCheckSquare, faCoffee)


                    Then use it like this:



                    import React from 'react'
                    import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'

                    export const Beverage = () => (
                    <div>
                    <FontAwesomeIcon icon="check-square" />
                    Favorite beverage: <FontAwesomeIcon icon="coffee" />
                    </div>
                    )


                    Otherwise, you can use explicit imports:



                    import ReactDOM from 'react-dom'
                    import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
                    import { faCoffee } from '@fortawesome/free-solid-svg-icons'

                    const element = <FontAwesomeIcon icon={faCoffee} />

                    ReactDOM.render(element, document.body)


                    All this bits of details are explained here. The above examples are from there.






                    share|improve this answer













                    If you want to reference the icon by its name you have to declare a library:



                    import ReactDOM from 'react-dom'
                    import { library } from '@fortawesome/fontawesome-svg-core'
                    import { fab } from '@fortawesome/free-brands-svg-icons'
                    import { faCheckSquare, faCoffee } from '@fortawesome/free-solid-svg-icons'

                    library.add(fab, faCheckSquare, faCoffee)


                    Then use it like this:



                    import React from 'react'
                    import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'

                    export const Beverage = () => (
                    <div>
                    <FontAwesomeIcon icon="check-square" />
                    Favorite beverage: <FontAwesomeIcon icon="coffee" />
                    </div>
                    )


                    Otherwise, you can use explicit imports:



                    import ReactDOM from 'react-dom'
                    import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
                    import { faCoffee } from '@fortawesome/free-solid-svg-icons'

                    const element = <FontAwesomeIcon icon={faCoffee} />

                    ReactDOM.render(element, document.body)


                    All this bits of details are explained here. The above examples are from there.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jan 18 at 16:17









                    GramatiikGramatiik

                    8710




                    8710























                        0














                        It could be that you are spelling 'fortawesome' and not 'fontawesome'






                        share|improve this answer
























                        • Oddly, that's how it's specified in the docs. fontawesome.com/how-to-use/on-the-web/using-with/react

                          – isherwood
                          Jan 18 at 16:11











                        • @isherwood Weird, I didn't check the docs, just glanced over his code. I wonder why they did that

                          – remoo
                          Jan 18 at 16:12











                        • IIRC fortawesome used to be their domain. Maybe before they got the big $ from the kickstarter

                          – engineerDave
                          Jan 18 at 16:23
















                        0














                        It could be that you are spelling 'fortawesome' and not 'fontawesome'






                        share|improve this answer
























                        • Oddly, that's how it's specified in the docs. fontawesome.com/how-to-use/on-the-web/using-with/react

                          – isherwood
                          Jan 18 at 16:11











                        • @isherwood Weird, I didn't check the docs, just glanced over his code. I wonder why they did that

                          – remoo
                          Jan 18 at 16:12











                        • IIRC fortawesome used to be their domain. Maybe before they got the big $ from the kickstarter

                          – engineerDave
                          Jan 18 at 16:23














                        0












                        0








                        0







                        It could be that you are spelling 'fortawesome' and not 'fontawesome'






                        share|improve this answer













                        It could be that you are spelling 'fortawesome' and not 'fontawesome'







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Jan 18 at 16:11









                        remooremoo

                        248




                        248













                        • Oddly, that's how it's specified in the docs. fontawesome.com/how-to-use/on-the-web/using-with/react

                          – isherwood
                          Jan 18 at 16:11











                        • @isherwood Weird, I didn't check the docs, just glanced over his code. I wonder why they did that

                          – remoo
                          Jan 18 at 16:12











                        • IIRC fortawesome used to be their domain. Maybe before they got the big $ from the kickstarter

                          – engineerDave
                          Jan 18 at 16:23



















                        • Oddly, that's how it's specified in the docs. fontawesome.com/how-to-use/on-the-web/using-with/react

                          – isherwood
                          Jan 18 at 16:11











                        • @isherwood Weird, I didn't check the docs, just glanced over his code. I wonder why they did that

                          – remoo
                          Jan 18 at 16:12











                        • IIRC fortawesome used to be their domain. Maybe before they got the big $ from the kickstarter

                          – engineerDave
                          Jan 18 at 16:23

















                        Oddly, that's how it's specified in the docs. fontawesome.com/how-to-use/on-the-web/using-with/react

                        – isherwood
                        Jan 18 at 16:11





                        Oddly, that's how it's specified in the docs. fontawesome.com/how-to-use/on-the-web/using-with/react

                        – isherwood
                        Jan 18 at 16:11













                        @isherwood Weird, I didn't check the docs, just glanced over his code. I wonder why they did that

                        – remoo
                        Jan 18 at 16:12





                        @isherwood Weird, I didn't check the docs, just glanced over his code. I wonder why they did that

                        – remoo
                        Jan 18 at 16:12













                        IIRC fortawesome used to be their domain. Maybe before they got the big $ from the kickstarter

                        – engineerDave
                        Jan 18 at 16:23





                        IIRC fortawesome used to be their domain. Maybe before they got the big $ from the kickstarter

                        – engineerDave
                        Jan 18 at 16:23











                        -1














                        Firstly you should use npm to install the react package




                        npm i -g yarn



                        yarn add react-native-fontawesome




                        After this you must import the data to start using in your project



                        import FontAwesome, { Icons } from 'react-native-fontawesome';

                        ...
                        render() {
                        return (
                        <View>
                        <Text style={{margin: 10, fontSize: 15, textAlign: 'left'}}>
                        <FontAwesome>{Icons.chevronLeft}</FontAwesome>
                        Text
                        </Text>
                        </View>
                        );
                        },


                        if you want a more complete tutorial you can access the tutorial clicking here






                        share|improve this answer




























                          -1














                          Firstly you should use npm to install the react package




                          npm i -g yarn



                          yarn add react-native-fontawesome




                          After this you must import the data to start using in your project



                          import FontAwesome, { Icons } from 'react-native-fontawesome';

                          ...
                          render() {
                          return (
                          <View>
                          <Text style={{margin: 10, fontSize: 15, textAlign: 'left'}}>
                          <FontAwesome>{Icons.chevronLeft}</FontAwesome>
                          Text
                          </Text>
                          </View>
                          );
                          },


                          if you want a more complete tutorial you can access the tutorial clicking here






                          share|improve this answer


























                            -1












                            -1








                            -1







                            Firstly you should use npm to install the react package




                            npm i -g yarn



                            yarn add react-native-fontawesome




                            After this you must import the data to start using in your project



                            import FontAwesome, { Icons } from 'react-native-fontawesome';

                            ...
                            render() {
                            return (
                            <View>
                            <Text style={{margin: 10, fontSize: 15, textAlign: 'left'}}>
                            <FontAwesome>{Icons.chevronLeft}</FontAwesome>
                            Text
                            </Text>
                            </View>
                            );
                            },


                            if you want a more complete tutorial you can access the tutorial clicking here






                            share|improve this answer













                            Firstly you should use npm to install the react package




                            npm i -g yarn



                            yarn add react-native-fontawesome




                            After this you must import the data to start using in your project



                            import FontAwesome, { Icons } from 'react-native-fontawesome';

                            ...
                            render() {
                            return (
                            <View>
                            <Text style={{margin: 10, fontSize: 15, textAlign: 'left'}}>
                            <FontAwesome>{Icons.chevronLeft}</FontAwesome>
                            Text
                            </Text>
                            </View>
                            );
                            },


                            if you want a more complete tutorial you can access the tutorial clicking here







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jan 18 at 16:18









                            Super PenguinoSuper Penguino

                            1




                            1






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54257590%2fhow-to-use-fontawesome-in-react%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Liquibase includeAll doesn't find base path

                                How to use setInterval in EJS file?

                                Petrus Granier-Deferre