calibreapp/react-live-chat-loader

Unable to use Custom Button

dave-smartystreets opened this issue · 6 comments

This code from the README.md file...

import { useChat } from 'react-live-chat-loader'

export const LoadChatButton = () => {
  const [state, loadChat] = useChat()

  return <button onClick={loadChat}>Load Chat</button>
}

... throws the following error:

Server Error
TypeError: Cannot destructure property 'loadWhenIdle' of 'undefined' as it is undefined.

Hi @dave-smartystreets.

Can you confirm what Provider you are using? A complete example of your implementation with the Provider wrapping the hook will be helpful for us to debug.

Sure thing. We're using HelpScout.

Thanks. I can reproduce the bug. We seem to have lost the default value in the Typescript update. For now you can get around this by passing in an empty object or an object with loadWhenIdle set to false so it'll only load when you click your button. e.g.

const [state, loadChat] = useChat({})
const [state, loadChat] = useChat({loadWhenIdle: false})

Awesome, thanks for the help!

Whoops, @mikedijkstra I'll open up a PR to fix it.

@elmoeleven Great! I was just about to add another issue but won't do that now 😄