Similar to the issue in #1521, I am experiencing this with both defaultProps and propTypes.
eslint-plugin-react: 7.8.2
react-native: 0.55.3
export default class MyClass extends React.Component {
static defaultProps = {
style: null,
}
static propTypes = {
style: ViewPropTypes.style,
}
render() { // stuff }
}
The following results in:
Component should be written as a pure function.
Indeed, as it should - you should do this instead:
function MyClass() {
// stuff
}
MyClass.defaultProps = {
style: null,
};
MyClass.propTypes = {
style: ViewPropTypes.style,
};
export default MyClass;
Why is that preferred?
@offero because if it doesn't need to be a class, it shouldn't be - functional components are always preferred because they have no inherent mutable state.