File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change 11import { css , setup } from "goober" ;
2- import React , { useEffect , useState } from "react" ;
2+ import React , { useState } from "react" ;
3+ import { useDidUpdateEffect } from "./use-did-update-effect" ;
34
45import cc from "./classnames" ;
56import Tag from "./tag" ;
@@ -86,11 +87,11 @@ export const TagsInput = ({
8687} : TagsInputProps ) => {
8788 const [ tags , setTags ] = useState < any > ( value || [ ] ) ;
8889
89- useEffect ( ( ) => {
90+ useDidUpdateEffect ( ( ) => {
9091 onChange && onChange ( tags ) ;
9192 } , [ tags ] ) ;
9293
93- useEffect ( ( ) => {
94+ useDidUpdateEffect ( ( ) => {
9495 if ( JSON . stringify ( value ) !== JSON . stringify ( tags ) ) {
9596 setTags ( value ) ;
9697 }
Original file line number Diff line number Diff line change 1+ import { useEffect , useRef } from "react" ;
2+
3+ export function useDidUpdateEffect ( fn , inputs ) {
4+ const didMountRef = useRef ( false ) ;
5+
6+ useEffect ( ( ) => {
7+ if ( didMountRef . current ) fn ( ) ;
8+ else didMountRef . current = true ;
9+ } , inputs ) ;
10+ }
You can’t perform that action at this time.
0 commit comments