How to add !important
into my inline CSS property?
If I add it after 2px
it just ignore whole style.
import React from "react";
export default class Todo extends React.Component {
render() {
const {text} = this.props;
const cardStyles = {
borderWidth: '2px'
};
return (
<div class="card mb-2 border" style={cardStyles}>
<div class="card-body">
<h5 class="card-title m-0">{text}</h5>
</div>
</div>
)
}
}
Inline styles are styles defined using the style attributes. They can also be normal or important.
Rule of Thumb. The official React documentation frowns upon the use of inline styling as a primary means of styling projects and recommends the use of the className attribute instead.
One of the main benefits of using React JS is its potential to reuse components. It saves time for developers as they don't have to write various codes for the same features. Furthermore, if any changes are made in any particular part, it will not affect other parts of the application.
To use inline styles in React, use the style attribute, which accepts a Javascript object with camelCased properties.
Apparently it is not supported https://github.com/facebook/react/issues/1881#issuecomment-262257503
meanwhile you can use a hack doing:
<div ref={element => {
if (element) element.style.setProperty('border', '2px', 'important');
}}
/>
It appears it currently isn't supported based on this GitHub issue https://github.com/facebook/react/issues/1881
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With