I'm trying to create a button component in react js. I'm able to render the bootstrap classes. But, I need to override some css rules in bootstrap. for that I have created a styles variable. But, it's throwing error.
parent.js
<Button buttonType={TYPES.DANGER} label="Add To Cart" onClick={() => this.addItemToCart(pdpList.uniqueID)}></Button>
button.js
import React from 'react';
const styles ={
background-color: #EF3829 !important;
color: #fff;
border-radius: 0px !important;
}
export const TYPES = {
PRIMARY: 'btn-primary',
WARNING: 'btn-warning',
DANGER: 'btn-danger',
SUCCESS: 'btn-success',
}
export const Button = (props) => (
<button
onClick={props.onClick}
className={props.styles,[ props.buttonType || TYPES.PRIMARY] }
>
{props.label}
</button>
);
Can some please help me to troubleshoot this problem.
className={props.styles,[ props.buttonType || TYPES.PRIMARY] }This expression is equivalent to[ props.buttonType || TYPES.PRIMARY](this is how comma operator works) making className an array of 1 element while it should be a string.