1
- import React , { useState } from 'react' ;
1
+ import React , { useCallback , useEffect , useState } from 'react' ;
2
2
import { CommonUtils } from '@utils/Common' ;
3
3
import Theme from '@utils/Theme' ;
4
4
import classname from 'classnames' ;
@@ -19,20 +19,31 @@ const Index = ({ projectNavOptions, searchOption = {}, triggerSearch, type }) =>
19
19
} ) ;
20
20
const [ isActive , setActive ] = useState ( false ) ;
21
21
22
- const search = ( e ) => {
23
- e . preventDefault ( ) ;
22
+ const search = useCallback ( ( ) => {
24
23
triggerSearch ( {
25
24
...selected ,
26
25
searchQuery : query ,
27
26
type,
28
27
} ) ;
29
- } ;
28
+ } , [ query , selected , triggerSearch , type ] ) ;
29
+
30
+ const handleSearch = useCallback (
31
+ ( e ) => {
32
+ e . preventDefault ( ) ;
33
+ search ( ) ;
34
+ } ,
35
+ [ search ]
36
+ ) ;
37
+
38
+ useEffect ( ( ) => {
39
+ search ( ) ;
40
+ } , [ selected , type ] ) ;
30
41
31
42
const toggleDropDown = ( dropdown ) => setDropdown ( dropdown ) ;
32
43
const selectOption = ( type ) => ( option ) => select ( { ...selected , [ type ] : option } ) ;
33
44
return (
34
45
< div className = { theme . art_sel_area } >
35
- < form onSubmit = { search } >
46
+ < form onSubmit = { handleSearch } >
36
47
{ Object . keys ( SearchOptionMap )
37
48
. filter ( ( key ) => searchOption [ key ] )
38
49
. map ( ( key ) => {
@@ -61,7 +72,7 @@ const Index = ({ projectNavOptions, searchOption = {}, triggerSearch, type }) =>
61
72
< button
62
73
type = "button"
63
74
className = { classname ( theme . btn_srch , theme . imbtn_pop_srch ) }
64
- onClick = { search }
75
+ onClick = { handleSearch }
65
76
>
66
77
< span className = { theme . blind } >
67
78
{ CommonUtils . getLang ( 'Menus.search_lang' ) }
0 commit comments