From 655be4404630a20ae4ca40c4af84afcc2e63557b Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Thu, 2 Nov 2023 15:36:21 +0100
Subject: refactor(hooks): replace useInputAutofocus with useAutofocus hook

* extract setTimeout logic using useTimeout
* change condition to be a function
* return a ref
---
 src/components/organisms/toolbar/search.tsx | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

(limited to 'src/components/organisms/toolbar/search.tsx')

diff --git a/src/components/organisms/toolbar/search.tsx b/src/components/organisms/toolbar/search.tsx
index 6a33aff..4429770 100644
--- a/src/components/organisms/toolbar/search.tsx
+++ b/src/components/organisms/toolbar/search.tsx
@@ -1,8 +1,7 @@
-import { forwardRef, type ForwardRefRenderFunction, useRef } from 'react';
+import { forwardRef, type ForwardRefRenderFunction } from 'react';
 import { useIntl } from 'react-intl';
-import { useInputAutofocus } from '../../../utils/hooks';
+import { useAutofocus } from '../../../utils/hooks';
 import { BooleanField, type BooleanFieldProps, Icon } from '../../atoms';
-import { FlippingLabel } from '../../molecules';
 import { SearchModal, type SearchModalProps } from '../modals';
 import searchStyles from './search.module.scss';
 import sharedStyles from './toolbar-items.module.scss';
@@ -43,11 +42,9 @@ const SearchWithRef: ForwardRefRenderFunction<HTMLDivElement, SearchProps> = (
         description: 'Search: Open label',
       });
 
-  const searchInputRef = useRef<HTMLInputElement>(null);
-  useInputAutofocus({
-    condition: isActive,
+  const searchInputRef = useAutofocus<HTMLInputElement>({
+    condition: () => isActive,
     delay: 360,
-    ref: searchInputRef,
   });
 
   return (
-- 
cgit v1.2.3

