1

In react.js I want to use a css style like this

<button class = "btn btn-primary"> A Button </ button>
import style1 from './style.css'
return <button className = {s['btn btn-primary']}> A Button </ button>;

How do I do it?

1
  • <button className = {'btn btn-primary'}> A Button </ button> Commented Aug 2, 2018 at 6:00

1 Answer 1

2

Well you can just simply place the classes as a string, like this:

<button className="btn btn-primary"> A Button </ button>

or if you have complex classes with logic, you can use this great package:

https://www.npmjs.com/package/classnames

<button className={classNames({ foo: true, bar: false })}> A Button </button>

this will result to this html:

<button class="foo"> A Button </button>
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.