Giter Club home page Giter Club logo

Comments (2)

SuppSoftAdminZ avatar SuppSoftAdminZ commented on May 11, 2024 1

Thanks!! I ended up using this on in the onClick event and it works perfectly.
onClick={() => convoClicked(node.messageId,node.messageSubject)}

from chat-ui-kit-react.

supersnager avatar supersnager commented on May 11, 2024

@SuppSoftAdminZ Each conversation usually has a unique id. It can be a conference id or a user id depending on your implementation. You can use this id in the onClick handler.
How you keep the state in your application is up to you. For example you can use the local useState/useReducer, Redux, or React context.

Here is an example using the local state.

const conversations = [
  { id: 0, name: "Joe" },
  { id: 1, name: "Lilly" },
  { id: 2, name: "Patrick" }
];

// Messages are indexed by conversation id
const = messages = {
  1: [
    { message: "message 1"}, 
    { message: "message 2"}
  ],
 2: [
    { message: "message 3"}, 
    { message: "message 4"}
  ]
....
}

const [currentConversation, setCurrentConversation] = useState(0);

<ConversationList>
  {conversations.map( c => <Conversation key={c.id} name={c.name}
                                         onClick={() => setCurrentConversation(c.id)} />)  }
</ConversationList>

// Render message list from current conversation
<MessageList>
  {messages[currentConversation].map( (m,idx) => <Message key={idx} model={m} />)}
</MessageList>

This is a naive implementation, but you get the idea.

Good news:

This week I will be releasing a beta version of my new chat state management library.
It's based on react context and hooks.

It has some nice features:

  • ready to use methods for adding messages
  • tracking state of grouped messages
  • tracking state of conversations and current conversation
  • support for debounced typing indicator
  • and so on....

I think this library will be useful for you.

from chat-ui-kit-react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.