Skip to content

Commit

Permalink
fix(react-instantsearch): use → addMiddlewares (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhayab committed Aug 10, 2023
1 parent bcc1e6e commit 350fb42
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ function DropdownMiddleware({
closeOnChange,
close,
}: MiddlewareProps) {
const { use } = useInstantSearch();
const { addMiddlewares } = useInstantSearch();

useEffect(() =>
use(() => ({
addMiddlewares(() => ({
onStateChange() {
const shouldCloseOnChange =
closeOnChange === true ||
Expand Down
6 changes: 3 additions & 3 deletions react-instantsearch/remix/components/ScrollTo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ type ScrollToProps = ComponentProps<'div'> & {
};

export function ScrollTo({ children, ...props }: ScrollToProps) {
const { use } = useInstantSearch();
const { addMiddlewares } = useInstantSearch();
const containerRef = useRef<HTMLDivElement>(null);

useEffect(() => {
return use(() => {
return addMiddlewares(() => {
return {
onStateChange() {
const isFiltering = document.body.classList.contains('filtering');
Expand All @@ -27,7 +27,7 @@ export function ScrollTo({ children, ...props }: ScrollToProps) {
},
};
});
}, [use]);
}, [addMiddlewares]);

return (
<div {...props} ref={containerRef}>
Expand Down
6 changes: 3 additions & 3 deletions react-instantsearch/remix/components/SearchErrorToast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import * as Toast from '@radix-ui/react-toast';
import { useInstantSearch } from 'react-instantsearch';

export function SearchErrorToast() {
const { use } = useInstantSearch();
const { addMiddlewares } = useInstantSearch();
const [error, setError] = useState<Error | null>(null);

useEffect(() => {
return use(({ instantSearchInstance }) => {
return addMiddlewares(({ instantSearchInstance }) => {
function handleError(searchError: Error) {
setError(searchError);
}
Expand All @@ -21,7 +21,7 @@ export function SearchErrorToast() {
},
};
});
}, [use]);
}, [addMiddlewares]);

if (!error) {
return null;
Expand Down

0 comments on commit 350fb42

Please sign in to comment.