Closed
Description
Hi,
Try this code:
import React from 'react';
import PropTypes from 'prop-types';
class Test extends React.Component {
constructor(props) {
super(props);
this.state = {
foo: false,
};
}
onFoo() {
this.setState((prevState, props) => {
props.doSomething();
return {
foo: true,
};
});
}
render() {
return (
<div>{this.state.foo}</div>
);
}
}
Test.propTypes = {
doSomething: PropTypes.func.isRequired,
};
export default Test;
You will get an error on line doSomething: PropTypes.func.isRequired,
despite that doSomething
is used inside the async version of setState()
. Yep, I know, it's a strange usage, but it should be handled imho ;)
Thanks!
Activity
ljharb commentedon Oct 29, 2017
Very strange usage; but yes, it should work.
Fix no-unused-prop-types arrow callbacks
Fix no-unused-prop-types arrow callbacks
Fix no-unused-prop-types arrow callbacks
Fix no-unused-prop-types arrow callbacks
Fix no-unused-prop-types arrow callbacks
petersendidit commentedon Oct 29, 2017
This is very similar to #1477 but fixable because the prop usage isn't in an arrow function that is an attribute to a JSX node. My research into fixing #1477 will work here.
Fix no-unused-prop-types setState updater