Remove deprecated UNSAFE_componentWillUpdate in SLDSDataTable#3053
Remove deprecated UNSAFE_componentWillUpdate in SLDSDataTable#3053DNiederweis wants to merge 2 commits intosalesforce:masterfrom
Conversation
…apshotBeforeUpdate
|
Thanks for opening this pull request! 💯 This is a community-driven project, and we can't do it without your participation. Please check out our contributing 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. |
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 the React 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 cloned site repo to confirm the site will function correctly at the next release.