pusher / chatkit-client-react

React client SDK for Pusher Chatkit
MIT License
1 stars 1 forks source link

Enable errors to be handled on Chatkit setup #8

Open sir-dunxalot opened 4 years ago

sir-dunxalot commented 4 years ago

Is your feature request related to a problem? Please describe. If there is a connection error when initiating the ChatkitProvider HOC, there is no way to catch the error (that I know of). For example, the following code throws and error in the console but the error can't be caught in a functional component so no error can be shown to the user:

export default function Chat() {
  const instanceLocator = process.env.CHATKIT_INSTANCE_LOCATOR;
  const tokenProvider = new TokenProvider({
    url: `http://localhost:3000/api/chat-token`,
  });

  return (
    <div className="chat">
      <ChatkitProvider
        instanceLocator={instanceLocator}
        tokenProvider={tokenProvider}
        userId='a-completely-fake-user-id'
      >
        { ... }
      </ChatkitProvider>
    </div>
  );
}

Describe the solution you'd like I would like a hook, event like .onInitError(), or ability to pass in an onInitError() callback to the ChatkitProvider.

Describe alternatives you've considered I could presumably handle the error inside a child component when accessing the chatkit instance but this will be ineffective when my HOC contains several child components, which is the case in my app, like <ChatContacts /><ChatMessages /><ChatInput />. In this case, handling the error message in any of these components would result in either 1) the two other components rendered or visible or 2) a convoluted process of passing the error back to the parent HOC Chatkit component.

Additional context Add any other context or screenshots about the feature request here.