- No need to follow Rails's convention here.
- For lists of things, use
ItemList
instead ofItems
to be more clear.
class ItemsIndexPage extends ...
class ItemsList extends ...
class ItemIndexPage extends ...
class ItemList extends
// Because HubspotDealListPage might be too verbose
class HubspotDealsPage extends ...
- Validating w/
isRequired
has not been useful for our codebase. Remove them. - But if we're open sourcing a component, use it.
static propTypes = {
foo: PropTypes.array.isRequired
};
static propTypes = {
foo: PropTypes.array
};
export default class Foo extends Component {
render () {
return <div></div>
}
}
const Foo ({ ... }) => (
<div></div>
)
// Better to name a class instead of using an anonymous function
// so it can be debugged easily on devtools
export default Foo
Use defaultProps
instead of select
(mapStateToProps
) to assign default values coming in from the store/do null check
- You can use
defaultProps
orselect
(mapStateToProps
) to assign default values. You may need this to avoid unexpected errors b/c of passingundefined
. - Prefer
defaultProps
for this because that's what it's meant for. Keepselect
to do just one thing: selecting stuff from state.
render () {
this.props.list.map(...) // Can skip null check
}
...
function select(state) {
return {
list: state.list || []
}
}
export default connect(select)(...)
static defaultProps = {
list: []
};
render () {
this.props.list.map(...) // Can skip null check
}
...
function select(state) {
return {
list: state.list
}
}
export default connect(select)(...)