From 80b71edf184bfa688cac0686c20e387768e3cbf1 Mon Sep 17 00:00:00 2001 From: Jack Allen Date: Mon, 24 Jun 2019 15:04:04 +0100 Subject: [PATCH] fix(index.js): Replaced the deprecated `componentWillReceiveProps`. --- src/index.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/index.js b/src/index.js index 746ae4876..f7d0ca049 100644 --- a/src/index.js +++ b/src/index.js @@ -133,15 +133,18 @@ class ReactTooltip extends React.Component { this.bindWindowEvents(resizeHide) // Bind global event for static method } - componentWillReceiveProps (props) { - const { ariaProps } = this.state - const newAriaProps = parseAria(props) - + static getDerivedStateFromProps (nextProps, prevState) { + const { ariaProps } = prevState + const newAriaProps = parseAria(nextProps) const isChanged = Object.keys(newAriaProps).some(props => { return newAriaProps[props] !== ariaProps[props] }) - if (isChanged) { - this.setState({ ariaProps: newAriaProps }) + if (!isChanged) { + return null + } + return { + ...prevState, + ariaProps: newAriaProps } }