There is a common CSS-in-JS solution in the React community: styled-components。Unfortunately, however,
styled-components uses the
<style> tag to dynamically control styles, and there is no similar solution in mini program. But we can achieve the same functionality with linaria,
linaria mainly provides the following features.
- API that approximates
- TypeScript support
- Zero runtime
linaria is also very simple, first installing the dependencies via NPM:
babel.config.js in the project root directory:
After that, configure
Finally, create a new
linaria.config.js in the root of the project
In the business code we can use it like this.
The community has another option Fower，Documentation