1- import { FC , memo , useMemo } from 'react' ;
1+ import { FC , memo , useEffect , useMemo , useState } from 'react' ;
22import { determineInputType , searchValue } from 'src/utilities/search-helper-methods' ;
33import { useNavigate } from 'react-router-dom' ;
44import styled , { useTheme } from 'styled-components' ;
@@ -8,7 +8,7 @@ import {LightBlack, Slate} from '../assets/styles/colors';
88import { useAppDispatch , useAppSelector } from '../utilities/hooks' ;
99import { changeCurrency , changeNetwork } from 'src/store/app.actions' ;
1010import { Pill } from './pill' ;
11- import { size } from 'src/utilities/constants' ;
11+ import { size } from 'src/utilities/constants' ;
1212
1313const SearchInput = styled . input `
1414 background: none;
@@ -52,15 +52,21 @@ const Search: FC<SearchProps> = ({borderBottom, id, setErrorMessage}) => {
5252 const theme = useTheme ( ) ;
5353 const dispatch = useAppDispatch ( ) ;
5454 const { currency, network} = useAppSelector ( ( { APP } ) => APP ) ;
55+ const [ isMobile , setIsMobile ] = useState ( window . innerWidth < Number ( size . mobileL . slice ( 0 , - 2 ) ) ) ;
5556
5657 const searchIcon = theme . dark ? SearchDarkSvg : SearchLightSvg ;
5758 const searchId = id || 'search' ;
5859
60+ useEffect ( ( ) => {
61+ window . addEventListener ( 'resize' , ( ) => {
62+ setIsMobile ( window . innerWidth < Number ( size . mobileL . slice ( 0 , - 2 ) ) ) ;
63+ } ) ;
64+ } , [ ] ) ;
65+
5966 const search = async ( event : any ) => {
6067 event . preventDefault ( ) ;
6168 setErrorMessage ( '' ) ;
6269 const searchVal = event . target [ searchId ] . value . replace ( / \s / g, '' ) ;
63-
6470 const searchInputs = await determineInputType ( searchVal ) ;
6571 if ( searchInputs . length ) {
6672 try {
@@ -161,7 +167,6 @@ const Search: FC<SearchProps> = ({borderBottom, id, setErrorMessage}) => {
161167 }
162168
163169 const searchInputPlaceholder = useMemo ( ( ) => {
164- const isMobile = window . innerWidth < Number ( size . mobileL . slice ( 0 , - 2 ) ) ;
165170 let placeholder = 'Search for block, transaction, or address' ;
166171 if ( currency && network ) {
167172 if ( isMobile ) {
@@ -170,7 +175,7 @@ const Search: FC<SearchProps> = ({borderBottom, id, setErrorMessage}) => {
170175 placeholder = `${ placeholder } on ${ currency } ${ network } ` ;
171176 }
172177 return placeholder ;
173- } , [ currency , network , window . innerWidth ] ) ;
178+ } , [ currency , network , isMobile ] ) ;
174179
175180 return (
176181 < SearchForm onSubmit = { search } borderBottom = { borderBottom } >
0 commit comments