score:3

Accepted answer

React has getDefaultProps. Then you can call onClick without errors.

getDefaultProps: function() {
    return {
        onClick: function() {}
    };
}

score:0

You could do with typeof:

if (typeof this.props.onClick === 'function'){
    //...
}

score:10

i am using anonymous empty arrow function... correct me if this is stupid :)

component.defaultProps = {
  foo: () => {},
};

Related Query

More Query from same tag