Skip to content

Instantly share code, notes, and snippets.

@tommmyy
Created May 28, 2019 10:40
Show Gist options
  • Save tommmyy/796f3566ae12bb977bc2b65d726c56ea to your computer and use it in GitHub Desktop.
Save tommmyy/796f3566ae12bb977bc2b65d726c56ea to your computer and use it in GitHub Desktop.
Extending component
// BEFORE:
const CommentTextArea = ({ maxCharacters, name, validate, ...otherProps }) => (
<TextareaField
name={name}
rows={4}
label={<Message {...messages.comment} />}
maxCharacters={maxCharacters}
{...otherProps}
/>
);
CommentTextArea.propTypes = {
maxCharacters: PropTypes.number,
name: PropTypes.string,
};
CommentTextArea.defaultProps = {
maxCharacters: 256,
name: 'comment',
};
// AFTER:
const CommentTextArea = props => <TextareaField {...props} />;
CommentTextArea.propTypes = {
maxCharacters: PropTypes.number,
name: PropTypes.string.isRequired,
rows: PropTypes.number,
};
CommentTextArea.defaultProps = {
maxCharacters: 256,
rows: 4,
label: <Message {...messages.comment} />,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment