Skip to content

Commit

Permalink
Merge pull request #1252 from youluna/feat-lifecycle-balloon
Browse files Browse the repository at this point in the history
chore(Balloon): update lifecycle
  • Loading branch information
myronliu347 authored Nov 11, 2019
2 parents e117213 + 7c5e13b commit 56181c9
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/balloon/balloon.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import { polyfill } from 'react-lifecycles-compat';
import Overlay from '../overlay';
import { func, obj, log } from '../util';
import BalloonInner from './inner';
Expand Down Expand Up @@ -27,7 +28,7 @@ const alignList = [
let alignMap = normalMap;

/** Balloon */
export default class Balloon extends React.Component {
class Balloon extends React.Component {
static contextTypes = {
prefix: PropTypes.string,
};
Expand Down Expand Up @@ -205,18 +206,17 @@ export default class Balloon extends React.Component {
this._onVisibleChange = this._onVisibleChange.bind(this);
}

componentWillReceiveProps(nextProps) {
if ('visible' in nextProps) {
this.setState({
visible: nextProps.visible,
});
static getDerivedStateFromProps(props) {
const nextState = {};
if ('visible' in props) {
nextState.visible = props.visible;
}

if ('align' in nextProps && alignList.includes(nextProps.align)) {
this.setState({
align: nextProps.align,
});
if ('align' in props && alignList.includes(props.align)) {
nextState.align = props.align;
}

return nextState;
}

_onVisibleChange(visible, trigger) {
Expand Down Expand Up @@ -388,3 +388,5 @@ export default class Balloon extends React.Component {
);
}
}

export default polyfill(Balloon);

0 comments on commit 56181c9

Please sign in to comment.