Comments (3)
A couple things I've seen using react-css in production:
classes
method gets huge, quick. this could be a side effect of having too large of classes in the first place, but what i like about inline styles is that the styles are defined with the component. what i found was that we ended up with these huge classes
functions defining all of these styles and they became unwieldy fast.
i think class components themselves tend to become really large. i've started using stateless components which make composing components much easier. i'm not sure how these work with the current API of ReactCSS (i know v2 was on the horizon at some point).
i haven't looked into the technical details, but something like radium's api: https://github.com/FormidableLabs/radium#usage is interesting because i could do something like:
const MyStatelessComponent = () => {
const styles = {text: {color: 'black'}};
return <div><span style={styles.text}>"hi"</span></div>;
}
export { MyStatelessComponent };
export Radium(MyStatelessComponent);
if ReactCSS is a HoC we could do the same thing which would definitely be interesting.
from reactcss.
While switching over to ReactCss for my personal website, I created a basic higher-order component, see https://gist.github.com/nheyn/ac4f4200313fd34d81ee.
It is a little bit of a hack, I had to make a "dummy Component" to bind to the inline(...)
function. It was the only way to get the classes object from the Component (that was passed to the higher-order component) and return it from this.classes(...)
in inline(...)
.
Other then that, it's similar to Component.js. The main differences are:
- The
css(...)
method is added to the props of the passed in Component - The
css(...)
method (now a prop) must be passed the classes object (I added it as the 1st argument) - The
styles(...)
method must always be defined
Here is one of the Components (with some simplifications) that uses the higher-order component:
import React from 'react';
import useStyles from '../useStyles';
const Section = React.createClass({
contextTypes: {
screenSize: React.PropTypes.string.isRequired
},
styles() {
const { screenSize } = this.context;
return this.props.css(this.classes(), {
smallScreen: screenSize === 'xs' || screenSize === 'sm'
});
},
classes() {
return {
'default': {
section: {
position: 'absolute',
left: '10%',
right: '10%',
heynioColors: 'default'
}
},
'smallScreen': {
section: {
left: 0,
right: 0
}
}
};
},
render() {
const style = this.styles();
return (
<section style={style.section}>
{this.props.children}
</section>
);
}
});
export default useStyles(Section);
from reactcss.
The API has been changed in 1.0.0 to make this unnecessary!
from reactcss.
Related Issues (20)
- Remove react-addons-test-utils from peerDependencies HOT 8
- react-addons-test-utils still in published 1.0.8 HOT 1
- Custom selectors that are vendor specific HOT 2
- Pass in onClick component for Hover
- how to used Autoprefixing ? HOT 1
- Autoprefix returning empty list under webpack2 HOT 2
- Build fails while using with react-color component HOT 5
- Make Autoprefixing Exhaustive
- Proposal: Support for symbols
- Redux Compatibility? HOT 4
- Put react in dependencies cause npm install different react version, HOT 1
- Tag releases please HOT 1
- Hover.js > hover.js HOT 1
- ReactCSSTransitionGroup example HOT 5
- Is Hover broken? HOT 3
- Why is there an example titled Redux? HOT 1
- Pseudo-classes are not pseudo-elements (documentation nitpick) HOT 1
- Remove lodash as a dependency and use lodash 4.0 submodules as needed HOT 2
- Input Placeholder Color HOT 1
- Write type declaration file for typescript HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reactcss.