
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.
so-react-chat-widget
Advanced tools

npm install --save react-chat-widget
yarn add react-chat-widget
1- Add the Widget component to your root component
import React, { Component } from 'react';
import { Widget } from 'react-chat-widget';
import 'react-chat-widget/lib/styles.css';
class App extends Component {
render() {
return (
<div className="App">
<Widget />
</div>
);
}
}
export default App;
2- The only required prop you need to use is the handleNewUserMessage, which will receive the input from the user.
import React, { Component } from 'react';
import { Widget } from 'react-chat-widget';
import 'react-chat-widget/lib/styles.css';
class App extends Component {
handleNewUserMessage = (newMessage) => {
console.log(`New message incoming! ${newMessage}`);
// Now send the message throught the backend API
}
render() {
return (
<div className="App">
<Widget
handleNewUserMessage={this.handleNewUserMessage}
/>
</div>
);
}
}
export default App;
3- Import the methods for you to add messages in the Widget. (See messages)
import React, { Component } from 'react';
import { Widget, addResponseMessage } from 'react-chat-widget';
import 'react-chat-widget/lib/styles.css';
class App extends Component {
componentDidMount() {
addResponseMessage("Welcome to this awesome chat!");
}
handleNewUserMessage = (newMessage) => {
console.log(`New message incoming! ${newMessage}`);
// Now send the message throught the backend API
addResponseMessage(response);
}
render() {
return (
<div className="App">
<Widget
handleNewUserMessage={this.handleNewUserMessage}
/>
</div>
);
}
}
export default App;
4- Customize the widget to match your app design! You can add both props to manage the title of the widget and the avatar it will use. Of course, feel free to change the styles the widget will have in the CSS
import React, { Component } from 'react';
import { Widget, addResponseMessage, addLinkSnippet, addUserMessage } from 'react-chat-widget';
import 'react-chat-widget/lib/styles.css';
import logo from './logo.svg';
class App extends Component {
componentDidMount() {
addResponseMessage("Welcome to this awesome chat!");
}
handleNewUserMessage = (newMessage) => {
console.log(`New message incoming! ${newMessage}`);
// Now send the message throught the backend API
}
render() {
return (
<div className="App">
<Widget
handleNewUserMessage={this.handleNewUserMessage}
profileAvatar={logo}
title="My new awesome title"
subtitle="And my cool subtitle"
/>
</div>
);
}
}
export default App;
| type | required | default value | description | |
|---|---|---|---|---|
| handleNewUserMessage | PropTypes.func | YES | Function to handle the user input, will receive the full text message when submitted | |
| title | PropTypes.string | NO | 'Welcome' | Title of the widget |
| subtitle | PropTypes.string | NO | 'This is your chat subtitle' | Subtitle of the widget |
| senderPlaceHolder | PropTypes.string | NO | 'Type a message...' | The placeholder of the message input |
| profileAvatar | PropTypes.string | NO | The profile image that will be set on the responses | |
| titleAvatar | PropTypes.string | NO | The picture image that will be shown next to the chat title | |
| showCloseButton | PropTypes.bool | NO | false | Show or hide the close button in full screen mode |
| fullScreenMode | PropTypes.bool | NO | false | Allow the use of full screen in full desktop mode |
| badge | PropTypes.number | NO | 0 | Display a notification badge on the launcher if the value is greater than 0 |
| autofocus | PropTypes.bool | NO | true | Autofocus or not the user input |
| launcher | PropTypes.func | NO | Custom Launcher component to use instead of the default |
To change the styles you need the widget to have, simply override the CSS classes wrapping them within the containers and add your own style to them! All classes are prefixed with rcw- so they don't override your other classes in case you are not hasing them.
To verride, you can do, for expample:
.rcw-conversation-container > .rcw-header {
background-color: red;
}
.rcw-message > .rcw-response {
background-color: black;
color: white;
}
That way, you can leave the JS clean and keep the styles within the CSS.
If you want to add new messages, you can use the following methods:
addResponseMessage
addUserMessage
addLinkSnippet
{
title: 'My awesome link',
link: 'https://github.com/Wolox/react-chat-widget',
target: '_blank'
}
target value is _blank which will open the link in a new window.renderCustomComponent
Markdown is supported for the responses and user messages.
You can also control certain actions of the widget:
toggleWidget
toggleInputDisabled
You can use a custom component for the Launcher if you need one that's not the default, simply use the launcher prop like:
launcher={handleToggle => this.getCustomLauncher(handleToggle)}
getCustomLauncher() is a method that will return the Launcher component. By default, the function passed by that prop, will receive the handleToggle parameter which is the method that will toggle the widget.
For example, if you want to use a simple button to toggle the widget:
launcher={handleToggle => (
<button onClick={handleToggle}>Toggle</button>
)}
This project is maintained by Martín Callegari and it was written by Wolox.

FAQs
Chat web widget for React apps
We found that so-react-chat-widget 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.