Fredrik
Fredrik
TTCTheo's Typesafe Cult
Created by Fredrik on 10/11/2023 in #questions
How does the top-level hook rule work within other hooks?
And as long as you have the eslint rule the beginner would not be allowed to make the change above, so then it should be fine anyway
8 replies
TTCTheo's Typesafe Cult
Created by Fredrik on 10/11/2023 in #questions
How does the top-level hook rule work within other hooks?
👍 Thanks for your answer all the same! 🙏
8 replies
TTCTheo's Typesafe Cult
Created by Fredrik on 10/11/2023 in #questions
How does the top-level hook rule work within other hooks?
Fair, got the response elsewhere that whiile the current setup is valid in regards to the top-level hook rule, it might be good practice to still do alt 2 to avoid someone with not as much react knowledge to come in and do something like:
export const useToken = (shouldUseCookieStore: boolean) => ({ value: shouldUseCookieStore ? useCookieStore(s => s.value) : useTokenStore(s => s.value) })
export const useToken = (shouldUseCookieStore: boolean) => ({ value: shouldUseCookieStore ? useCookieStore(s => s.value) : useTokenStore(s => s.value) })
Rather than
const useToken = (shouldUseCookieStore: boolean) => {
const value = useTokenStore(s => s.value)
const cookieValue = useCookieStore(s => s.value)
return { value: shouldUseCookieStore ? cookieValue : value }
}
const useToken = (shouldUseCookieStore: boolean) => {
const value = useTokenStore(s => s.value)
const cookieValue = useCookieStore(s => s.value)
return { value: shouldUseCookieStore ? cookieValue : value }
}
(psuedo code)
8 replies