logux / client

Logux base components to build web client
https://logux.org/
MIT License
656 stars 46 forks source link

Show error when client is not found in context #77

Closed AleksandrSl closed 2 years ago

AleksandrSl commented 3 years ago

useClient could return undefined, though types say that it shouldn't export function useClient(): Client Maybe adding something like this in useClient() will help if (!context) throw new Error('Wrap component with ClientContext.Provider')

My background: I called useClient in storyBook component, wrapping the story component the wrong way, and got cannot read type of undefined. It took a while to get the essence of a problem :smile:

ai commented 3 years ago

Yeap, let's throw an error (we can do it only in development mode since it is configuration issue and will be catched in development)

ai commented 3 years ago

Send PR

AleksandrSl commented 2 years ago

Actually, this was done in https://github.com/logux/client/pull/78/