0

I'm using TailwindCSS in a React Project. I'm able to style normal HTML elements by passing TailwindCSS utility classes in the className attribute but this doesn't work when I pass the utility classes inside a components className attribute like this:

<Dropdown className="hidden sm:block sm:ml-6"/> 

Dropdown is a React component imported into another component.

How do I make this work?

2
  • 1
    Import the tailwind css in global css file Commented Apr 27, 2020 at 1:03
  • The CSS file that Tailwind generates is already imported in the index.js of my React project. Commented Apr 27, 2020 at 1:11

1 Answer 1

3

if <Dropdown/> is your custom made component you probaly forgot to include in on the div inside your component definition,

you can rename "className" to customclass and apply it inside your component definition.

so with that your code would look like

<Dropdown customclasses="hidden sm:block sm:ml-6"/> 

and your component definition,

const Dropdown = ({ customclasses, ...otherProps }) => <div className={customclasses}></div> 

or if you dont want to change className you can spread the ...otherProps directly on the div

const Dropdown = ({ yourprop, yourprop , ...otherProps }) => <div {...otherProps}></div> 
Sign up to request clarification or add additional context in comments.

1 Comment

How come it doesn't need to be passed as prop in Vue.js?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.