Inspired by STRV's example project https://github.com/strvcom/React-Meetup
/components
/containers
/pages
-
Components
-
both
actions
anddata
are passed asprops
-
dumb components are easily testable
-
Containers - container components
-
use
@connect
decorator to wireredux
andprops
-
close to no logic
-
Pages - router pages
The normal way
/actions
/constants
/reducers
Less files, aka modules
/modules
- combines all parts from the above(constants, reducer and actions) in a single file
ES6, 7 transpiler configuration easy to forget about.
@connect(
state => ({
reviews: state.reviews // exposes props.reviews in decorated component
}),
dispatch => ({
change(paperId, questionId, value) { // exposes props.change in decorated component
dispatch(change(paperId, questionId, value))
},
submit(paperId, answers) { // exposes props.submit in decorated component
dispatch(submit(paperId, answers))
}
})
)
Waits for promise to resolve before rendering.
@asyncConnect([{
promise: ({ store: { dispatch, getState }, params }) => {
if (!isLoadedDetail(params.paperId, getState())) {
return dispatch(loadDetail(params.paperId))
}
}
},{
promise: ({ store: { dispatch, getState }, params }) => {
if (!isLoaded(getState())) {
return dispatch(load())
}
}
}])
Great for component specific styles.
https://github.com/webpack/css-loader
My example project https://github.com/stlk/paper-review/tree/master/webpack
.item {
margin: 0.5rem 0;
}
import styles from './comments.css'
<div className={styles.item}>No comments</div>
Result:
.comments__item___2XF9U {
margin: 0.5rem 0;
}
<div class="comments__item___2XF9U">No comments</div>
https://github.com/stlk/paper-review/blob/master/webpack/test/components/PapersListItem.js
Enzyme render methods: http://airbnb.io/enzyme/docs/api/index.html