enableOnlyWhenAllKeysTruthy
Description: If true, the action will only be executed when all keys resolve to true.
Default Value: false.
- How To: This is the preferred option for dependent fetches. Use
enableOnlyWhenAllKeysTruthy: truewhen a fetch should only occur if all parts of its key are truthy. This provides a concise and declarative way to manage dependencies within the key itself.// Correct: Fetch todos only if user ID is available in the keyconst { data: user } = useFetch('user', fetchUser); // key, actionconst todosFetch = useFetch(['todos', user?.id], // key contains null if user ID is missing() => fetchTodos(user.id),{ enableOnlyWhenAllKeysTruthy: true } // fetch only when user.id is truthy); - Best Practice: Avoid
enableOnlyWhenAllKeysTruthy: trueif you need more granular control over theenabledstate, or if some key parts can legitimately be falsy without disabling the fetch. In such cases, theenabledoption might be more suitable.