Skip to content

Commit ab77bfd

Browse files
massahoudoumassahoudou
authored andcommitted
refactor: Renamed state variable with default value true
-Removing the generic type from the `searchEmpty` - Renamed the state variable from `searchEmtpty` to `isSearchEmpty` for better naming. - Simplified the state declaration from `searchEmpty` to `isSearchEmpty`. - Set the default value of `isSearchEmpty` to `true` at initial .
1 parent 634fe01 commit ab77bfd

File tree

2 files changed

+5
-4888
lines changed

2 files changed

+5
-4888
lines changed

components/Hero.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ const { main: mainLanguages, others: otherLanguages } = languages;
1111

1212
function Hero() {
1313
const [errorMessage, setErrorMessage] = useState<string | null>(null);
14-
const [searchEmpty, setSearchEmpty] = useState<boolean>(false);
14+
const [isSearchEmpty, setIsSearchEmpty] = useState(true);
1515
const formRef = useRef<HTMLFormElement | null>(null);
1616
const router = useRouter();
1717
const handleClear: MouseEventHandler<HTMLButtonElement> = () => {
18-
if (formRef.current && !searchEmpty ) {
18+
if (formRef.current && !isSearchEmpty ) {
1919

2020
formRef.current.reset();
2121
setErrorMessage(null);
@@ -57,13 +57,13 @@ function Hero() {
5757
name="search"
5858
onChange={
5959
(e) => {
60-
setSearchEmpty(e.target.value.trim() === '') ;
61-
console.log(searchEmpty);
60+
setIsSearchEmpty(e.target.value.trim() === '') ;
61+
console.log(e.target.value.trim(),e.target.value.trim() === '' );
6262
}
6363
}
6464
/>
6565

66-
{!searchEmpty &&
66+
{!isSearchEmpty &&
6767
<button onClick={handleClear} className='absolute right-0 top-0 bottom-0 p-2'>
6868
<ClearIcon />
6969
</button>}

0 commit comments

Comments
 (0)