-
Notifications
You must be signed in to change notification settings - Fork 734
FeatureHighlight - migrate to new api, remove unsafe method #1290
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
Conversation
const target = nextProps?.getTarget?.(); | ||
const node = FeatureHighlight.findTargetNode(target); | ||
if (node && node !== prevState?.node) { | ||
return {...prevState, node}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why setting all '...prevState' and not only 'node'? What else has changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
contentPosition
, it works without setting it, but any future state change will be reset in prop change, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once a prop changed and getDerivedStateFromProps
is called you'll get the last state in 'prevState' parameter. Think of this function as setState()
, you don't need to set the whole state object again, only the part you want to change as a result of a prop change. When you don't return anything from this function, the default is 'null'. Returning null doesn't reset the state, it doesn't touch it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thanks!
} | ||
|
||
componentDidUpdate() { | ||
componentDidUpdate(nextProps) { | ||
if (!_.isEqual(nextProps, this.props)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really necessary to check all the props? All of them are relevant for setting the target position?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, fixed
} | ||
|
||
componentDidUpdate() { | ||
shouldSetTargetPosition = (nextProps) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like 'shouldComponentUpdate'... If it's not a pure component you can just implement that method instead and the component will not be updated if it doesn't meet the condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried it before and now again, it's not quite working.
the position of the FeatureHighlight
view is getting the previous data, that's why I went with this solution.
(I even tried !_.isEqual(nextProps, this.props)
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wierd. Ok...
@mendyEdri Where do we stand with this PR? |
Fixed what needed, you can review it :) |
Description
Replaced UNSAFE
componentWillReceiveProps
method withgetDerivedStateFromProps
Changelog
Infra: FeatureHighlight migrated to newer React api, replaced
UNSAFE
method withgetDerivedStateFromProps