Skip to content

Commit a1e4ff3

Browse files
refactor: ♻️ detact outside value changes (#27)
1 parent 29eec27 commit a1e4ff3

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-tag-input-component",
33
"description": "lightweight component for tag(s) input",
4-
"version": "1.1.2",
4+
"version": "1.1.3",
55
"license": "MIT",
66
"author": "Harsh Zalavadiya",
77
"repository": "https://github.com/hc-oss/react-tag-input-component",

src/index.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ export const TagsInput = ({
8888
onChange && onChange(tags);
8989
}, [tags]);
9090

91+
useEffect(() => {
92+
if (JSON.stringify(value) !== JSON.stringify(tags)) {
93+
setTags(value)
94+
}
95+
}, [value])
96+
9197
const handleOnKeyUp = e => {
9298
e.stopPropagation();
9399

stories/tags-input.stories.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const Page = () => {
3232
isEditOnRemove={isEditOnRemove}
3333
beforeAddValidate={beforeAddValidate}
3434
/>
35-
<div style={{ margin: "2rem 0", display: "flex", flexFlow: "row" }}>
35+
<div style={{ marginTop: "2rem" }}>
3636
<button
3737
onClick={() => setDisabled(!disabled)}
3838
style={{ marginRight: "2rem" }}
@@ -41,7 +41,7 @@ export const Page = () => {
4141
</button>
4242
<pre>Disable: {JSON.stringify(disabled)}</pre>
4343
</div>
44-
<div style={{ margin: "2rem 0", display: "flex", flexFlow: "row" }}>
44+
<div>
4545
<button
4646
onClick={() => setisEditOnRemove(!isEditOnRemove)}
4747
style={{ marginRight: "2rem" }}
@@ -50,6 +50,11 @@ export const Page = () => {
5050
</button>
5151
<pre>Keep Words on Backspace: {JSON.stringify(isEditOnRemove)}</pre>
5252
</div>
53+
<div>
54+
<button onClick={() => setSelected(["tangerine"])}>
55+
override value
56+
</button>
57+
</div>
5358
</div>
5459
);
5560
};

0 commit comments

Comments
 (0)