react-native-crisp-chat-sdk
react-native-crisp-chat-sdk copied to clipboard
onClose event / how to reset visible state?
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.
You can use show function in Crisp Library for show modal
+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 😕 ?
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 />}