What is the best practice defining a function defaultProps that is empty in ReactJS?
My solution so far is either an empty arrow function or a null value. Which way would be better?
MyComponent.defaultProps = {
onClick: () => {},
onClickNull: null,
};
onClickis defined or not, thennullelse use the null object pattern by declaring() => {}.nullorundefinedor leave the property off the defaults. If you don't need your code to know and want to be able to use it without any checks, use the no-op function. (I usually create a single no-op function I reuse, although with modern engines I guess there's really no good reason for that...)