ts-react-default-props

1.4.0 • Public • Published

ts-react-default-props

All credit goes to @decademoon and @RobRendell.

Usage

interface IProps {
  required: number;
  defaulted: number;
}

class Foo extends React.Component<IProps> {
  public static defaultProps = {
    defaulted: 0
  };
}

// Whichever way you prefer... The former does not require a function call
const FooWithDefaultProps = Foo as ComponentTypeWithDefaultProps<typeof Foo>;
const FooWithDefaultProps = withDefaultProps(Foo);

const f1 = <FooWithDefaultProps />; // error: missing 'required' prop
const f2 = <FooWithDefaultProps defaulted={0} />; // error: missing 'required' prop
const f3 = <FooWithDefaultProps required={0} />; // ok
const f4 = <FooWithDefaultProps required={0} defaulted={0} />; // ok

Package Sidebar

Install

npm i ts-react-default-props

Weekly Downloads

1

Version

1.4.0

License

MIT

Unpacked Size

7.7 kB

Total Files

6

Last publish

Collaborators

  • rssbnjmn