2

I have kept the buttn.css and button.js in the same folder in my react app.But css is not rendering.

Button.css

.Button {
    background-color: transparent;
    border: none;
    color: white;
    outline: none;
    cursor: pointer;
    font: inherit;
    padding: 10px;
    margin: 10px;
    font-weight: bold;
}

.Button:first-of-type {
    margin-left: 0;
    padding-left: 0;
}

.Success {
    color: #5C9210;
}

.Danger {
    color: #944317;
}

Button.js

import React from 'react';
import classes from './Button.css';
const Button = (props) => (
  <button
  className={[classes.Button,classes[props.btnType]].join(' ')}
  onClick={props.clicked}>{props.children}</button>
);

export default Button;

Please suggest how to proceed without having to make a common css sheet for all the elements.

2
  • 1
    How have you attempted to debug so far? Have you console.log'd what [classes.Button,classes[props.btnType]].join(' ') evaluates to? Have you used browser dev tools to see if any of the CSS classes are being applied? Commented May 18, 2020 at 18:46
  • No, browser is unable to discover the css class Commented May 18, 2020 at 19:32

1 Answer 1

4

If you are using create-react-app your css file should be named Button.module.css.

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.