Comments (2)
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.
@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)
- Using defaultProps is deprecated HOT 1
- Keep position after adding new items
- Custom sendButton icon HOT 4
- Load long messages at the top rather than bottom
- MessageList gradually scrolling out of view when new message is received
- Custom container along with <MessageList> for custom user forms HOT 2
- Keep disabled MessageInput sendButton when text is none even if props is given. HOT 1
- Conversation list is not shown in phone HOT 1
- Formatting AvatarGroup in ConversationHeader HOT 3
- React-level dynamic theming/css style
- Typing effect animation HOT 3
- Bug: null is not an object (evaluating 't.scrollTop')
- the input message show value when paste the same value continuously but the state of value not update
- How to put a date under message
- MessageGroup.Footer with Avatar looks odd
- Expose onKeyPress for MessageInput
- Allow using send button when there is no message text HOT 3
- Scroll to message on browser-native find
- Regarding Chat Reply UI of one another user HOT 1
- IOS 16 version issue of clicking button as Message.CustomContent HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chat-ui-kit-react.