Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit 8426d47

Browse files
author
Jean Carlos Farias
authored
Merge pull request #1 from asseinfo/fix-warnings
Fix warnings on react of componentWillReceiveProps
2 parents 017c2ed + 3bc73a2 commit 8426d47

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-tagsinput",
3-
"version": "3.19.0",
3+
"version": "3.20.0",
44
"description": "Highly customizable React component for inputing tags",
55
"main": "react-tagsinput.js",
66
"peerDependencies": {

react-tagsinput.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -545,20 +545,20 @@
545545
});
546546
}
547547
}, {
548-
key: 'componentWillReceiveProps',
549-
value: function componentWillReceiveProps(nextProps) {
548+
key: 'componentDidUpdate',
549+
value: function componentDidUpdate(prevProps) {
550550
/* istanbul ignore next */
551551
if (this.hasControlledInput()) {
552552
return;
553553
}
554554

555-
if (!this.inputValue(nextProps)) {
555+
if (!this.inputValue(this.props)) {
556556
return;
557557
}
558558

559-
this.setState({
560-
tag: this.inputValue(nextProps)
561-
});
559+
if (this.inputValue(prevProps) !== this.inputValue(this.props)) {
560+
this.setState({ tag: this.inputValue(this.props) });
561+
}
562562
}
563563
}, {
564564
key: 'render',

src/index.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ class TagsInput extends React.Component {
8282
constructor () {
8383
super()
8484
this.state = {tag: '', isFocused: false}
85-
this.focus = ::this.focus
86-
this.blur = ::this.blur
85+
this.focus = this.focus.bind(this)
86+
this.blur = this.blur.bind(this)
8787
}
8888

8989
static propTypes = {
@@ -420,19 +420,19 @@ class TagsInput extends React.Component {
420420
})
421421
}
422422

423-
componentWillReceiveProps (nextProps) {
423+
componentDidUpdate (prevProps) {
424424
/* istanbul ignore next */
425425
if (this.hasControlledInput()) {
426426
return
427427
}
428428

429-
if (!this.inputValue(nextProps)) {
429+
if (!this.inputValue(this.props)) {
430430
return
431431
}
432432

433-
this.setState({
434-
tag: this.inputValue(nextProps)
435-
})
433+
if (this.inputValue(prevProps) !== this.inputValue(this.props)) {
434+
this.setState({ tag: this.inputValue(this.props) })
435+
}
436436
}
437437

438438
render () {
@@ -474,27 +474,27 @@ class TagsInput extends React.Component {
474474
return renderTag({
475475
key: index,
476476
tag,
477-
onRemove: ::this.handleRemove,
477+
onRemove: this.handleRemove.bind(this),
478478
disabled,
479-
getTagDisplayValue: ::this._getTagDisplayValue,
479+
getTagDisplayValue: this._getTagDisplayValue.bind(this),
480480
...tagProps
481481
})
482482
})
483483

484484
let inputComponent = renderInput({
485485
ref: r => { this.input = r },
486486
value: this._tag(),
487-
onPaste: ::this.handlePaste,
488-
onKeyDown: ::this.handleKeyDown,
489-
onChange: ::this.handleChange,
490-
onFocus: ::this.handleOnFocus,
491-
onBlur: ::this.handleOnBlur,
492-
addTag: ::this.addTag,
487+
onPaste: this.handlePaste.bind(this),
488+
onKeyDown: this.handleKeyDown.bind(this),
489+
onChange: this.handleChange.bind(this),
490+
onFocus: this.handleOnFocus.bind(this),
491+
onBlur: this.handleOnBlur.bind(this),
492+
addTag: this.addTag.bind(this),
493493
...this.inputProps()
494494
})
495495

496496
return (
497-
<div ref={r => { this.div = r }} onClick={::this.handleClick} className={className}>
497+
<div ref={r => { this.div = r }} onClick={this.handleClick.bind(this)} className={className}>
498498
{renderLayout(tagComponents, inputComponent)}
499499
</div>
500500
)

test/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ describe("TagsInput", () => {
660660
assert.equal(comp.len(), 1, "there should be one tag")
661661
});
662662

663-
describe("componentWillReceiveProps", () => {
663+
describe("componentDidUpdate", () => {
664664
it("updates the state", () => {
665665
class TestParent extends React.Component {
666666
constructor() {

0 commit comments

Comments
 (0)