Skip to content

Commit

Permalink
fix(react): do not call onClose on very first render
Browse files Browse the repository at this point in the history
  • Loading branch information
vanbasten17 committed Nov 12, 2020
1 parent 6573daa commit 03ce2ec
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/botonic-react/src/webchat/webchat.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ export const Webchat = forwardRef((props, ref) => {
setCurrentAttachment,
// eslint-disable-next-line react-hooks/rules-of-hooks
} = props.webchatHooks || useWebchat()
const firstUpdate = useRef(true)
const theme = merge(webchatState.theme, props.theme)
const { initialSession, initialDevSettings, onStateChange } = props
const isOnline = useNetwork()
Expand Down Expand Up @@ -647,6 +648,10 @@ export const Webchat = forwardRef((props, ref) => {
}

useEffect(() => {
if (firstUpdate.current) {
firstUpdate.current = false
return
}
if (webchatState.isWebchatOpen && props.onOpen) props.onOpen()
if (!webchatState.isWebchatOpen && props.onClose) {
props.onClose()
Expand Down

0 comments on commit 03ce2ec

Please sign in to comment.