0

I am using Fontawesome icons in my react and I am using CSS modules in react. Now I want to use this Icon so I am using the following syntax : <i className={styles['fa-user-circle']} ></i> I cant use normal syntax styles.someClassName because of hyphens in the name of fontawesome icons and also I need to combine fas and fa-user-circle classNames . How do I do that?

Thanks.

8
  • 1
    have you checked this out? fontawesome.com/how-to-use/on-the-web/using-with/react Commented Dec 18, 2018 at 7:59
  • ill check it out and let you know if it works . fingers crossed! Commented Dec 18, 2018 at 8:01
  • 1
    If you want to use multiple classnames, you can achieve it using something like: <div classNames={[styles['fa-user-circle'], styles['fas'] ].join(' ')} /> Commented Dec 18, 2018 at 8:05
  • Thanks it works but how do I customize I want to change its color and so on ? Commented Dec 18, 2018 at 8:05
  • the react component of fa works! how do I customize it Commented Dec 18, 2018 at 8:06

1 Answer 1

1

You can use the FontAwesome React version here

Implementation of it looks like

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faPlus } from '@fortawesome/free-solid-svg-icons'

and your render component looks like

 export default (props) => {
  return (
    <div>
      <FontAwesomeIcon icon={faPlus} className="pointer" onClick={props.onAdd} id={props.id} />
    </div>
 )
}

As you can see className we can give so whatever the extra CSS you want to give you can.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.