Skip to content
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

Warning: componentWillReceiveProps has been renamed #166

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions dist/react-input-autosize.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,22 @@ var generateId = function generateId() {

var AutosizeInput = function (_Component) {
inherits(AutosizeInput, _Component);
createClass(AutosizeInput, null, [{
key: 'getDerivedStateFromProps',

// https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props
value: function getDerivedStateFromProps(props, state) {
var id = props.id;

if (id !== state.prevPropId) {
return _extends({}, state, {
inputId: id || generateId(),
prevPropId: id
});
}
return null;
}
}]);

function AutosizeInput(props) {
classCallCheck(this, AutosizeInput);
Expand All @@ -269,7 +285,8 @@ var AutosizeInput = function (_Component) {

_this.state = {
inputWidth: props.minWidth,
inputId: props.id || generateId()
inputId: props.id || generateId(),
prevPropId: null
};
return _this;
}
Expand All @@ -281,15 +298,6 @@ var AutosizeInput = function (_Component) {
this.copyInputStyles();
this.updateInputWidth();
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
var id = nextProps.id;

if (id !== this.props.id) {
this.setState({ inputId: id || generateId() });
}
}
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate(prevProps, prevState) {
Expand Down
28 changes: 18 additions & 10 deletions dist/react-input-autosize.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,22 @@ var generateId = function generateId() {

var AutosizeInput = function (_Component) {
inherits(AutosizeInput, _Component);
createClass(AutosizeInput, null, [{
key: 'getDerivedStateFromProps',

// https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props
value: function getDerivedStateFromProps(props, state) {
var id = props.id;

if (id !== state.prevPropId) {
return _extends({}, state, {
inputId: id || generateId(),
prevPropId: id
});
}
return null;
}
}]);

function AutosizeInput(props) {
classCallCheck(this, AutosizeInput);
Expand All @@ -275,7 +291,8 @@ var AutosizeInput = function (_Component) {

_this.state = {
inputWidth: props.minWidth,
inputId: props.id || generateId()
inputId: props.id || generateId(),
prevPropId: null
};
return _this;
}
Expand All @@ -287,15 +304,6 @@ var AutosizeInput = function (_Component) {
this.copyInputStyles();
this.updateInputWidth();
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
var id = nextProps.id;

if (id !== this.props.id) {
this.setState({ inputId: id || generateId() });
}
}
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate(prevProps, prevState) {
Expand Down
2 changes: 1 addition & 1 deletion dist/react-input-autosize.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 19 additions & 10 deletions lib/AutosizeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ var generateId = function generateId() {
var AutosizeInput = function (_Component) {
_inherits(AutosizeInput, _Component);

_createClass(AutosizeInput, null, [{
key: 'getDerivedStateFromProps',

// https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props
value: function getDerivedStateFromProps(props, state) {
var id = props.id;

if (id !== state.prevPropId) {
return _extends({}, state, {
inputId: id || generateId(),
prevPropId: id
});
}
return null;
}
}]);

function AutosizeInput(props) {
_classCallCheck(this, AutosizeInput);

Expand All @@ -87,7 +104,8 @@ var AutosizeInput = function (_Component) {

_this.state = {
inputWidth: props.minWidth,
inputId: props.id || generateId()
inputId: props.id || generateId(),
prevPropId: null
};
return _this;
}
Expand All @@ -99,15 +117,6 @@ var AutosizeInput = function (_Component) {
this.copyInputStyles();
this.updateInputWidth();
}
}, {
key: 'componentWillReceiveProps',
value: function componentWillReceiveProps(nextProps) {
var id = nextProps.id;

if (id !== this.props.id) {
this.setState({ inputId: id || generateId() });
}
}
}, {
key: 'componentDidUpdate',
value: function componentDidUpdate(prevProps, prevState) {
Expand Down
19 changes: 13 additions & 6 deletions src/AutosizeInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,31 @@ const generateId = () => {
};

class AutosizeInput extends Component {
// https://reactjs.org/blog/2018/03/27/update-on-async-rendering.html#updating-state-based-on-props
static getDerivedStateFromProps (props, state) {
const { id } = props;
if (id !== state.prevPropId) {
return {
...state,
inputId: id || generateId(),
prevPropId: id
}
}
return null;
}
constructor (props) {
super(props);
this.state = {
inputWidth: props.minWidth,
inputId: props.id || generateId(),
prevPropId: null
};
}
componentDidMount () {
this.mounted = true;
this.copyInputStyles();
this.updateInputWidth();
}
componentWillReceiveProps (nextProps) {
const { id } = nextProps;
if (id !== this.props.id) {
this.setState({ inputId: id || generateId() });
}
}
componentDidUpdate (prevProps, prevState) {
if (prevState.inputWidth !== this.state.inputWidth) {
if (typeof this.props.onAutosize === 'function') {
Expand Down