}>
diff --git a/apps/scandic-web/components/Forms/BookingWidget/FormContent/Search/SearchList/List/ListItem/index.tsx b/apps/scandic-web/components/Forms/BookingWidget/FormContent/Search/SearchList/List/ListItem/index.tsx
index fea9c7633..ad79b69dc 100644
--- a/apps/scandic-web/components/Forms/BookingWidget/FormContent/Search/SearchList/List/ListItem/index.tsx
+++ b/apps/scandic-web/components/Forms/BookingWidget/FormContent/Search/SearchList/List/ListItem/index.tsx
@@ -47,21 +47,13 @@ export function ListItemSkeleton() {
return (
-
+
-
+
-
+
-
+
)
}
diff --git a/apps/scandic-web/components/Forms/BookingWidget/FormContent/Search/SearchList/index.tsx b/apps/scandic-web/components/Forms/BookingWidget/FormContent/Search/SearchList/index.tsx
index afe44049d..073ab2edf 100644
--- a/apps/scandic-web/components/Forms/BookingWidget/FormContent/Search/SearchList/index.tsx
+++ b/apps/scandic-web/components/Forms/BookingWidget/FormContent/Search/SearchList/index.tsx
@@ -1,5 +1,5 @@
"use client"
-import { useEffect, useState } from "react"
+import { useEffect } from "react"
import { useFormContext } from "react-hook-form"
import { useIntl } from "react-intl"
import { useDebounceValue } from "usehooks-ts"
@@ -23,6 +23,7 @@ import styles from "./searchList.module.css"
import type { SearchListProps } from "@/types/components/search"
export default function SearchList({
+ searchInputName,
getItemProps,
getMenuProps,
handleClearSearchHistory,
@@ -33,14 +34,14 @@ export default function SearchList({
}: SearchListProps) {
const lang = useLang()
const intl = useIntl()
- const [hasMounted, setHasMounted] = useState(false)
+
const {
clearErrors,
formState: { errors, isSubmitted },
} = useFormContext()
- const searchError = errors["search"]
+ const searchError = errors[searchInputName]
- const [debouncedSearch, setDebouncedSearch] = useDebounceValue(search, 250)
+ const [debouncedSearch, setDebouncedSearch] = useDebounceValue(search, 300)
useEffect(() => {
setDebouncedSearch(search)
@@ -57,14 +58,14 @@ export default function SearchList({
)
useEffect(() => {
- clearErrors("search")
- }, [search, clearErrors])
+ clearErrors(searchInputName)
+ }, [search, clearErrors, searchInputName])
useEffect(() => {
let timeoutID: ReturnType
| null = null
if (searchError) {
timeoutID = setTimeout(() => {
- clearErrors("search")
+ clearErrors(searchInputName)
// magic number originates from animation
// 5000ms delay + 120ms exectuion
}, 5120)
@@ -75,15 +76,7 @@ export default function SearchList({
clearTimeout(timeoutID)
}
}
- }, [clearErrors, searchError])
-
- useEffect(() => {
- setHasMounted(true)
- }, [setHasMounted])
-
- if (!hasMounted) {
- return null
- }
+ }, [clearErrors, searchError, searchInputName])
if (searchError && isSubmitted && typeof searchError.message === "string") {
if (searchError.message === "Required") {
@@ -166,7 +159,7 @@ export default function SearchList({
"We couldn't find a matching location for your search.",
})}