-
Notifications
You must be signed in to change notification settings - Fork 921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
componentWillReceiveProps -> componentDidUpdate #635
componentWillReceiveProps -> componentDidUpdate #635
Conversation
@mfix22 Here is actually bugless solution using componentDidUpdate method. export class EditableInput extends (PureComponent || Component) {
input = React.createRef();
...
componentDidUpdate(prevProps, prevState) {
const input = this.input.current || null;
if (
this.props.value !== this.state.value &&
(prevProps.value !== this.props.value || prevState.value !== this.state.value)
) {
if (input === document.activeElement) {
this.setState({
blurValue: String(this.props.value).toUpperCase()
});
} else {
this.setState({
value: String(this.props.value).toUpperCase(),
blurValue: !this.state.blurValue && String(this.props.value).toUpperCase()
});
}
}
}
...
render() {
...
<input
ref={this.input}
....
/>
...
} |
any updates on this one? |
@mfix22 there are 3 places that use componentWillReceiveProps, but this PR only fixed one of them |
@rinick is that preventing this PR from being merged? I can probably take a look at the other ones this weekend. I don't think it is a problem for them to come from separate PRs or even separate people. |
@casesandberg anything you need from me before merging this? Do you want to go the |
I'm not a maintainer of this this project, I just feel doing it right would increase the chance of it getting merged. These 3 places are basically the same issue. It would be really weird if it's fixed by 3 different people with 3 different PRs |
I just pushed the other 2 PRs. The maintainer can decide which to merge in where. 🤷♂ |
Looks great. This will be released shortly as |
Instead of using
componentDidUpdate
, you could also update this component to usegetDerivedStateFromProps
if you are willing to putthis.input
in state instead:Let me know if you all prefer one over the other.
Begin #634