Yoctol / react-messenger-customer-chat

React component for messenger customer chat plugin
MIT License
272 stars 69 forks source link

How can click on the other button and open the messenger? #60

Closed hamedhtm closed 3 years ago

hamedhtm commented 4 years ago

I want to click a button in the header and open messenger chat! how can do that?

kb1995 commented 4 years ago

Did you find any solutions for this?

jamcd commented 3 years ago

You can change the 'shouldShowDialog' prop to true dynamically to make the dialogue open. This works for me, but the issue I have is that it completely removes the messenger icon for a second or two before it reappears and then opens the dialogue.

I'm not sure why, but it seems to be causing some kind of re-render when you change that value.

chentsulin commented 3 years ago

I believe the shouldShowDialog prop should work in this case. For example, you could write something like this:

import React, { useState } from 'react';
import MessengerCustomerChat from 'react-messenger-customer-chat';

function MyComponent() {
  const [shouldShowDialog, setShouldShowDialog] = useState(false);
  const handleClick = () => {
    setShouldShowDialog(!shouldShowDialog);
  };

  return (
    <div>
      <button onClick={handleClick}>Click Me!</button>
      <MessengerCustomerChat
        pageId="<PAGE_ID>"
        appId="<APP_ID>"
        htmlRef="<REF_STRING>"
        shouldShowDialog={shouldShowDialog}
      />
    </div>
  );
}