This is code for tutorials I do as I learn React et al. Uses Webpack, React Hot Loader, React 0.14, Babel 6, ES6.
- Webpack / Hot Loader setup
- React
- React documentation - Tutorial - Comments
- SurviveJS Online Book - Kanban App
- React documentation - Thinking in React
- Redux
- Redux documentation - Basics - Todo List
- Redux documentation - Advanced - Reddit API
- Redux examples - TodoMVC
- React Router
- React Router documentation - Basics
I took some existing CSS and HTML and created some example code for 3 additional different styling methods: Inline Style in JS, CSS Modules, and Radium.
NOTE: the original CSS and HTML was done by my co-workers-- it is not my own code.
- CSS Stylesheet (original)
- Uses normal CSS (Sass) stylesheets
- CSS classes are set using the
classNameattribute of React elements
- Inline Style in JS
- Style information is put inside a Javascript object instead of CSS
- Doesn't support
:hoveror other pseudo selectors - Doesn't support media queries
- https://facebook.github.io/react/tips/inline-styles.html
- http://blog.vjeux.com/2014/javascript/react-css-in-js-nationjs.html
- https://www.youtube.com/watch?v=ERB1TJBn32c
- CSS Modules
- CSS is used but definitions are local to a module
- A CSS module is created for each Javascript module
- The Webpack CSS loader transforms the local CSS modules into global BEM-like CSS definitions
- http://glenmaddern.com/articles/css-modules
- https://www.youtube.com/watch?v=zR1lOuyQEt8
- https://github.com/css-modules/webpack-demo
- Doesn't have individual variables (use specific classes with composition or global Sass variables instead) css-modules/css-modules#22
- Use of child selectors goes against the encapsulation philosophy of CSS modules css-modules/css-modules#21
- It's possible to compose with external libraries like font awesome css-modules/css-modules#58 (comment)
- Radium
- This is like using #2 Inline Styles but it fixes some problems.
- Supports
:hover,:focus, and:active - Supports media queries
- Supports using an array of styles
- http://stack.formidable.com/radium/
- Not sure how to handle child selectors (same for regular inline style)
- Doesn't support
:before,:after,:checked, or:lastRadium FAQ Stack Overflow answer