diff --git a/.eslintrc.yml b/.eslintrc.yml index 6a2d536..6605860 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -24,6 +24,9 @@ rules: # disable no-unresolved since we don't install the deps # of our react example app import/no-unresolved: off + react/require-default-props: + - warn + - functions: defaultArguments jest/expect-expect: - warn - assertFunctionNames: diff --git a/README.md b/README.md index 7067b24..e0ec129 100644 --- a/README.md +++ b/README.md @@ -22,12 +22,8 @@ class TitleComponent extends Component { children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]), }; - static defaultProps = { - children: null, - }; - render() { - const {title, children} = this.props; + const {title, children = null} = this.props; return ( <> diff --git a/src/overridable.js b/src/overridable.js index 24be219..da362d4 100644 --- a/src/overridable.js +++ b/src/overridable.js @@ -36,7 +36,7 @@ export function parametrize(Component, extraProps) { /** * React component to enable overriding children when rendering. */ -function Overridable({id, children, ...restProps}) { +function Overridable({id = null, children = null, ...restProps}) { const overriddenComponents = useContext(OverridableContext); const child = children ? React.Children.only(children) : null; const childProps = child ? child.props : {}; @@ -62,16 +62,11 @@ Overridable.propTypes = { id: PropTypes.string, }; -Overridable.defaultProps = { - id: null, - children: null, -}; - /** * High-order component to override an existing React component and provide a new component instead. */ Overridable.component = (id, Component) => { - const Overridden = ({children, ...props}) => { + const Overridden = ({children = null, ...props}) => { const overriddenComponents = useContext(OverridableContext); const overriddenComponent = overriddenComponents[id]; return React.createElement(overriddenComponent || Component, props, children); @@ -79,9 +74,6 @@ Overridable.component = (id, Component) => { Overridden.propTypes = { children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]), }; - Overridden.defaultProps = { - children: null, - }; const name = Component.displayName || Component.name; Overridden.displayName = `Overridable(${name})`; Overridden.originalComponent = Component; diff --git a/src/overridable.test.js b/src/overridable.test.js index b7a1f4b..41129a4 100644 --- a/src/overridable.test.js +++ b/src/overridable.test.js @@ -10,13 +10,8 @@ class ExampleComponent extends Component { children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]), }; - static defaultProps = { - color: 'blue', - children: null, - }; - render() { - const {title, color, children} = this.props; + const {title, color = 'blue', children = null} = this.props; return ( <> diff --git a/src/store.test.js b/src/store.test.js index d2b72a0..fc9162d 100644 --- a/src/store.test.js +++ b/src/store.test.js @@ -9,12 +9,8 @@ class ExampleComponent extends Component { children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]), }; - static defaultProps = { - children: null, - }; - render() { - const {title, children} = this.props; + const {title, children = null} = this.props; return ( <>

{title}