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.

Access Denied

You must login or register for the workshop to view and run the tests.

Check out this video to see how the test tab works.