Is there a way to add external (eg. bootstrap) classes along with react-emotion styling?
import React, { Component } from 'react';
import { css } from 'react-emotion';
const MyStyle = css`
STYLE
`
export default class MyComponent extends Component {
render() {
return (<button className={css`${MyStyle}` /* add in some way `btn btn-default` */ }>Text</button>);
}
}
Thanks!
Emotion is a library designed for writing css styles with JavaScript. It provides powerful and predictable style composition in addition to a great developer experience with features such as source maps, labels, and testing utilities. Both string and object styles are supported.
This error is generated because the compiler is only able to import files from the src folder. Here, the CSS file is saved outside the src folder, so the compiler failed to import it. To make this code work, you just have to save the CSS file inside the src folder.
There are lots of ways to use Emotion, if you're using React, the easiest way to get started is to use the @emotion/react package. If you're not using React, you should use the @emotion/css package. To use it, import what you need, for example use the css prop to create class names with styles. Some hotpink text.
Emotions can play an important role in how you think and behave. The emotions you feel each day can compel you to take action and influence the decisions you make about your life, both large and small.
Yes you can. Below is the link where i had made a small example, the font colour is coming from react-emotion and background colour is coming from bootstrap.
import React, { Component } from 'react';
import { render } from 'react-dom';
import 'bootstrap/dist/css/bootstrap.min.css';
import styled, { css } from 'react-emotion'
const myStyle = css`
color: rebeccapurple;
`;
class App extends Component {
constructor() {
super();
this.state = {
name: 'React'
};
}
render() {
return (
<div className={myStyle + ' bg-primary'}>Hello World</div>
);
}
}
render(<App />, document.getElementById('root'));
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