#How to get the search param using useSearch() at the first time?
3 messages · Page 1 of 1 (latest)
const useSearchFirstTime = () => {
const [searchParam, setSearchParams] = useState<string | null | undefined>(
undefined,
);
const { search } = useSearch({
from: "/private-layout/home",
});
useEffect(() => {
setSearchParams(search);
}, []);
return searchParam;
};
I created the custom simple hook it works but I don't want useEffect and useState. Is there any alternative are there?
Put it in a ref
const { search } = useSearch(...);
const firstSearch = useRef(search);
firstSearch wont change.
Keep in mind that the component will still rerender.