3 ms·
I think using strings as an API is a step in the wrong direction. I like that it produces a React component directly though. We experimented with styling appro
by andreypopp 10y ago
I think using strings as an API is a step in the wrong direction. I like that it
produces a React component directly though.
We experimented with styling approaches for React a while ago and produced our
solution — React Stylesheet[1], which we used for over an year in different
React applications.
It also produces components out of style definitions directly:
let GreenBox = style('div', {
base: {
background: 'green'
}
})
Which you can use like any other React component later:
<GreenBox />
As you can see the API is kinda similar but uses JS instead of CSS string. What
are advantages? The following:
* Consistent syntax: you can use functions, variabls, mixins, w/o the need for
interpolation `${...}`.
* Tooling. This is big one. You can make your stylesheets linted with ESLint and
typesafe (!!!) with FlowType or TypeScript.
FlowType is supported out of the box, see [2]. Typesafe stylesheets is a huge
win for productivity, I constantly catch typos and invalid values via Flow.
[1]: https://github.com/prometheusresearch/react-stylesheet/blob/next/README.md https://github.com/prometheusresearch/react-stylesheet/blob/...
[2]: https://github.com/prometheusresearch/react-stylesheet/blob/next/README.md#type-safety https://github.com/prometheusresearch/react-stylesheet/blob/...
EDIT: additions
Styles are compiled into CSS so :hover and friends work here.
- mxstbr 10y agoHey Andrey! :wave: If you reading this are interested in a discussion about this, read this tweet by Andrey and the following replies: https://twitter.com/andreypopp/status/786524437843615744 https://twitter.com/andreypopp/status/786524437843615744 :)