- Notifications
You must be signed in to change notification settings - Fork433
Remove deprecated UNSAFE_componentWillUpdate in SLDSDataTable#3053
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Remove deprecated UNSAFE_componentWillUpdate in SLDSDataTable#3053
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Thanks for opening this pull request! 💯 This is a community-driven project, and we can't do it without your participation. Please check out ourcontributing guidelines and review the Contributor Checklist if you haven't already, to make sure everything is squared away. CircleCI will take about 10 minutes to run through the same items that are on the Contributor checklist with a pass/fail check below. Please fix any issues that cause CircleCI to fail or ask for clarification--we try, but sometimes the errors can be unclear. |
Uh oh!
There was an error while loading.Please reload this page.
Fixes # Deprecation Warning in console about UNSAFE_componentWillUpdate which "promotes unsafe coding practices" -React Blog
Additional description
While
UNSAFE_componentWillUpdateis called right before render,getSnapshotBeforeUpdateis called right before mutating the DOM. According to theReact Documentation, the combination ofgetSnapshotBeforeUpdateandcomponentDidUpdateshould cover all use cases for the legacycomponentWillUpdate.In this case since the purpose of using
UNSAFE_componentWillUpdateappeared to be resetting the interactive elements for the datatable if the props differed, I moved this logic intogetSnapshotBeforeUpdate. However, sincegetSnapshotBeforeUpdategets the previous props rather than the next props, the if-statement had to be slightly adjusted. Additionally, becausegetSnapshotBeforeUpdatemust contain a return statement(the return is passed as the third parameter tocomponentDidUpdate), it simply returns null. This change avoid the deprecation warning and enables the same behavior as withUNSAFE_componentWillUpdate.CONTRIBUTOR checklist (do not remove)
Please complete for every pull request
npm run lint:fixhas been run and linting passes.components/component-docs.jsonCI tests pass (npm test).REVIEWER checklist (do not remove)
components/component-docs.jsontests.Required only if there are markup / UX changes
last-slds-markup-reviewinpackage.jsonand push.last-accessibility-review, topackage.jsonand push.npm run local-updatewithin locally clonedsite repo to confirm the site will function correctly at the next release.