Proposal 1
Use CSS modules and colocate SCSS and component files.
// Card.jsx
import React from 'react';
import classNames from 'classnames/bind';
import styles from './card.scss';
const cx = classNames.bind(styles);
const Card = props =>
<div classNames=cx('card', { active: props.active }) />
Proposal 2
Colocate selectors with reducers.
import * as actions from './constants';
// Export reducer as default export
export default (currentState, action) => {
const initialState = {
races: {},
};
// ...
return newState;
}
// Export selectors as named exports
export const getActiveRaces = state =>
state.races.filter(r => r.active);
Selectors should operate on the same state as is defined in the reducer.
Prune the state in another place, if the reducer state is only a piece of the app's store.
import races, * as fromRaces from './races';
export default combineReducers({
// ...
races,
});
export const getActiveRaces = (state) =>
fromRaces.getActiveRaces(state.races);
Proposal 3
Separate files structure by domain instead of by function.
Separated by function.
actions/
api/
races.js
cards.js
index.js
nav.js
components/
Card.jsx
Nav.jsx
constants/
actions.js
containers/
CardWell.jsx
NavWell.jsx
reducers/
cards.js
index.js
nav.js
stores/
index.js
App.jsx
Separated by domain.
card/
actions.js
Card.jsx
constants.js
reducer.js
Well.jsx
nav/
actions.js
constants.js
Nav.jsx
reducer.js
Well.jsx
races/
actions.js
api.js
constants.js
reducer.js
stores/
index.js
App.jsx
Proposal 4
Each directory should define all exports in a single file, index.js and all other modules should only consume the exports defined in that file.
card/
actions.js
Card.jsx
constants.js
index.js
reducer.js
Well.jsx
// index.js
export * as actions from './actions';
export * as constants from './constants';
export default as Card from './Card';
// some-other.js
// NOT THIS
import * as cardConstants from '../card/constants';
import * as cardActions from '../card/actions';
import Card from '../card/Card';
// THIS
import { constants as cardConstants, actions as cardActions, Card } from '../card';
Proposal 1
Use CSS modules and colocate SCSS and component files.
Proposal 2
Colocate selectors with reducers.
Selectors should operate on the same state as is defined in the reducer.
Prune the state in another place, if the reducer state is only a piece of the app's store.
Proposal 3
Separate files structure by domain instead of by function.
Separated by function.
Separated by domain.
Proposal 4
Each directory should define all exports in a single file,
index.jsand all other modules should only consume the exports defined in that file.