johniak / react-web-gifted-chat

💬 The most complete chat UI for React
https://github.com/johniak/react-web-gifted-chat
MIT License
106 stars 60 forks source link
chat chatbot component javascript messenger react reactjs

Gifted Chat

Web fork of most complete chat UI for React Web (formerly known as Gifted Messenger).

Demo is available here

Article

The article how to create working chat in 20 minutes is available on medium - here

Features

Installation

Example

import { GiftedChat } from 'react-web-gifted-chat';

class Example extends React.Component {

  state = {
    messages: [],
  };

  componentWillMount() {
    this.setState({
      messages: [
        {
          id: 1,
          text: 'Hello developer',
          createdAt: new Date(),
          user: {
            id: 2,
            name: 'React',
            avatar: 'https://facebook.github.io/react/img/logo_og.png',
          },
        },
      ],
    });
  }

  onSend(messages = []) {
    this.setState((previousState) => ({
      messages: GiftedChat.append(previousState.messages, messages),
    }));
  }

  render() {
    return (
      <GiftedChat
        messages={this.state.messages}
        onSend={(messages) => this.onSend(messages)}
        user={{
          id: 1,
        }}
      />
    );
  }

}

Advanced example

See example/App.js for a working demo!

Message object

e.g.

{
  id: 1,
  text: 'My message',
  createdAt: new Date(Date.UTC(2016, 5, 11, 17, 20, 0)),
  user: {
    id: 2,
    name: 'React',
    avatar: 'https://facebook.github.io/react/img/logo_og.png',
  },
  image: 'https://facebook.github.io/react/img/logo_og.png',
  // Any additional custom parameters are passed through
}

Props

License

Notes for local development

You need to have facebook watchman installed

  1. cd example
  2. yarn
  3. yarn start
  4. yarn run sync in another terminal window (doesn't matter where)

If you have any issues, you can clear your watches using watchman watch-del-all and try again.

Author

Feel free to ask me question on Twitter @JanRomaniak!