Brett Jankord
Jul 28, 2017 · 1 min read

One of the biggest concerns I got from reading this was that prop-types / default-props weren’t at the top of the component making it harder to reason about a component.

As mentioned, you could use property initializers, but if you are on the fence on using that, you can define objects for your prop-types and default props before your class. And then attach them to the class after it is defined. This achieves more or less the same readability of being able to see all the prop-types / default props before the “inner workings” of the component.

const propTypes = {
children: PropTypes.node.isRequired,
icon: PropTypes.element,
isAnimated: PropTypes.bool,
onClose: PropTypes.func,
onOpen: PropTypes.func,
};

const defaultProps = {
isAnimated: false,
icon: <IconChevronRight />,
};

class Toggle extends React.Component {

}

Toggle.propTypes = propTypes;
Toggle.defaultProps = defaultProps;

export default Toggle;

    Brett Jankord

    Written by

    I am a front-end developer/designer/dreamer.