useCallback

Loading "useCallback"
๐Ÿ‘จโ€๐Ÿ’ผ We only call the setSearchParams function inside event handlers, so we don't have any problems, but we're making a reusable hook and we want to make certain people don't have problems if they need to use it in a useEffect or other hook that requires a dependency array. For example:
const [searchParams, setSearchParams] = useSearchParams()

useEffect(() => {
	if (someCondition) {
		setSearchParams({ foo: 'bar' })
	}
}, [setSearchParams, someCondition])
So I want you to wrap our setSearchParams function in useCallback to memoize it and avoid issues with the dependency array.
Login to get access to the exclusive discord channel.
  • General
    Welcome to EpicReact.dev! Say Hello ๐Ÿ‘‹
    Kent C. Dodds โ—† ๐Ÿš€๐Ÿ†๐ŸŒŒ:
    Welcome to the first of many posts in the EpicReact.dev channel! Take a moment to introduce yourself...
    0 ยท 4 days ago