
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-messaging
Advanced tools
THIS PACKAGE IS IN EARLY DEVELOPMENT!
The perfect React chat component.
npm i react-messaging
import React, { useState, useEffect } from 'react';
import { v4 } from 'uuid';
import { Chat } from 'react-messaging';
export function Example() {
const [messages, setMessages] = useState([]);
useEffect(() => {
initMessages();
}, []);
function initMessages() {
setMessages([
{
_id: '101',
text: 'Hello',
user: {
_id: '26',
name: 'Andrew Robertson',
username: 'RobboSZN',
avatar:
'https://tmssl.akamaized.net/images/portrait/originals/234803-1559827085.jpg',
},
date: new Date(),
},
{
_id: '102',
text: 'Hi',
user: {
_id: '100',
name: 'Jurgen Klopp',
username: 'KloppoSZN',
avatar:
'https://i.guim.co.uk/img/media/5445143eab4f7ab92cd015aff5140b60174308a9/162_10_1745_1047/master/1745.jpg?width=1200&height=1200&quality=85&auto=format&fit=crop&s=b017b1381457ec79ad4922db8e295a78',
},
date: new Date(),
},
]);
}
function onSend(text: string) {
setMessages([
...messages,
{
_id: v4(),
text,
user: CurrentUser,
date: new Date(),
},
]);
}
return (
<Chat
messages={messages}
user={CurrentUser}
onSend={(text) => onSend(text)}
/>
);
}
const CurrentUser = {
_id: '26',
name: 'Andrew Robertson',
username: 'RobboSZN',
avatar:
'https://tmssl.akamaized.net/images/portrait/originals/234803-1559827085.jpg',
};
export interface Message {
_id: string;
text: string;
user: User;
date: Date;
data?: any;
}
export interface User {
_id: string;
name?: string;
username?: string;
avatar?: string;
}
"Type a message...""hh:mm" (check date-fns docs to see valid formats)"MMMM do, yyyy" (check date-fns docs to see valid formats)false.Are your messages built different than the messages in the Message interface? That's why I made the useMessaging hook.
You have to give it an array of the original message objects, an object of the field names in the original message and a function (or an async function!) to get the user.
const arr = [
{
_id: '101',
text: 'Hello',
sender: '26',
date: new Date(),
},
{
_id: '102',
text: 'Hi',
sender: '100',
date: new Date(),
},
];
const users = [
{
_id: '26',
name: 'Andrew Robertson',
},
{
_id: '100',
name: 'Jurgen Klopp',
},
];
const { messages } = useMessaging({
original_messages: arr,
fields: {
text: 'text',
date: 'date',
user: {
id: '_id',
},
},
getUser: (message: any) => {
return users.find((user) => user._id === message.sender);
},
});
renderInput={(props) => (
<input
{...props} // required
type="text"/>
)}
For this example I'll use Material-UI's TextField
renderInput={(props) => (
<TextField
fullWidth
variant="outlined"
inputRef={props.ref} // the ref is different in this case
name={props.name} // not useful for this example, but it's important
label={'Type a message...'}
/>
)}
renderSend={(props) => (
<Button
{...props} // required
>
Send
</Button>
)}
renderMessage={(message, user) => (
<p>{user.username}: {message.text} ({format(message.text, 'kk:mm')})<p>
)}
renderText={(props, text) => (
<p>{text}</p>
)}
renderAvatar={(user) => (
<Avatar alt={user.name} src={user.avatar}/>
)}
Feel free to DM me on Twitter.
Copyright (c) 2020 Kfir Nevo
This project is licensed under the terms of the MIT license. See the MIT file.
FAQs
The perfect chat component for ReactJS
We found that react-messaging demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.