Answer the question
In order to leave comments, you need to log in
React Hook "useCategory" cannot be called inside a callback?
Here is my code
import React, { FC, useState,useMemo } from "react";
const FormSearch: FC<{ params: string }> = ({
params
}) => {
const [category, useCategory] = useState<string>("All");
const [search, setSearch] = useState<string>("");
useMemo(() => {
const searchParams = new URLSearchParams(params);
if (!!searchParams.get("Categories")&&!!searchParams.get("Search")) {
useCategory(`${searchParams.get("Categories")}`);
setSearch(`${searchParams.get("Search")}`);
} else {
setSearch("");
useCategory("All")
}
}, [params]);
return (
<div>1000</div>
);
};
Answer the question
In order to leave comments, you need to log in
This is a mistake about hooks. You have a category change handler that starts with use ...
rename it to setCategory
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question