react-native-crisp-chat-sdk icon indicating copy to clipboard operation
react-native-crisp-chat-sdk copied to clipboard

onClose event / how to reset visible state?

Open kylegillen opened this issue 2 years ago • 3 comments

This module opens up in its own window / view it seems.

The example folder has a state driven solution to showing and hiding the chat window, but with no onClose event what's the proposed solution to resetting the state?

There's an existing closed issue with the same question and an answer here: https://github.com/walterholohan/react-native-crisp-chat-sdk/issues/17#issuecomment-797669406

But the answer is nonsensical.

kylegillen avatar Jan 02 '23 04:01 kylegillen

You can use show function in Crisp Library for show modal

kasiri182 avatar Feb 02 '23 20:02 kasiri182

+1 @nextriot this would be very useful for a centralized top level management of Crisp. At the moment there is also this very annoying useEffect which opens the modal by default when the component is mounted : I wonder why this is necessary 😕 ?

ElpayetSupervan avatar Jun 23 '23 21:06 ElpayetSupervan

I couldn't render the chat for the second time because of this issue, so I ended up counting how many times it was opened and using the show function on every subsequent open. Here's my code if anyone has the same problem:

import { useState, useRef } from 'react'
import { show } from 'react-native-crisp-chat-sdk'

export const useSupportChat = () => {
  const [renderChat, setRenderChat] = useState(false)
  const counter = useRef(0)

  return {
    renderChat,
    showChat: () => {
      // workaround for the weird CrispChat behaviour
      if (counter.current === 0) {
        setRenderChat(true)
      } else {
        show()
      }

      counter.current += 1
    },
  }
}

Then, in the component:

const { renderChat, showChat } = useSupportChat()

{renderChat && <CrispChat />}

kamilpodlasek avatar Jul 14 '23 09:07 kamilpodlasek