Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.1k views
in Technique[技术] by (71.8m points)

javascript - OnClick of Button called twice only when I first time click on it

I am having a minor issue, I am creating a web application with integrated chat so when I have OnClick that listens for clicks and open the proper chat with user (I am calling it chatHead). When I open first chatHead it always gets called twice for some reason, first with it's normal and expected behaviour and the second time passing undefined as parameter. After this whenever I open some other chatHead I don't have a problem with this nor if I close the first chatHead and open it again. Application is working without crashing but my console displays an error and I just can't let it go :D. I know it's trivial but for some reason I can't figure out what it is. Below is the button I make for every chatHead with a clickListener.

<Accordion defaultActiveKey="-1">
  <Card>
    <Accordion.Collapse eventKey={conversation.id}>
      <Launcher
        isOpen={conversation.opened}
        agentProfile={{
          teamName: conversation.toProduct.userName,
          imageUrl:
            "https://a.slack-edge.com/66f9/img/avatars-teams/ava_0001-34.png",
        }}
        onMessageWasSent={onAddMessage}
        messageList={messages}
      />
    </Accordion.Collapse>
    <Card.Header>
      <Accordion.Toggle
        as={Button}
        style={{ width: "100%" }}
        eventKey={conversation.id}
        onClick={() => props.openChat(conversation)}
      >
        {conversation.toProduct.userName}
      </Accordion.Toggle>
    </Card.Header>
  </Card>
</Accordion>

props.openChat is a action I am dispatching, I have used injectIntl in order to dispatch it. Conversation is object from list of conversations which parent component .maps and then sends to this component if you need to know but I think that this isn't so important for the problem.

Thank you all for your time


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...