score:11

Accepted answer

You can use the following:

const defaultProps: IProps = {
   size: 'default',
   onClick: () => void(0)
};

score:3

I usually do

MyComponent.defaultProps = {
  someNoop: f => f
}

as something that is short, easy to type, and will just return undefined.

score:4

I think using lodashes noop might be a good option because depending on the number of re-renders the component will have BEFORE the component has access to the prop, it will create that many references to an anonymous function that essentially is a place holder for the function you need. Something like:

import noop from 'lodash/noop';
MyComponent.defaultProps = {
  myfunc: noop,
};

Its a small optimization but also prevents the developer from creating an anonymous function for every default prop declaration that a func is needed in.

score:29

You cannot use void in javascript as return value. Instead of void, use null as return value.

onClick: () => null

Related Query

More Query from same tag