@nlxchat/react
    TypeScript icon, indicating that this package has built-in type declarations

    0.5.1 • Public • Published

    React hook wrapper for the NLX Chat SDK

    This package provides a custom useChat hook which you can use to build your own chat widget in React like so:

    Installation

    npm install --save @nlxchat/react react react-dom

    Usage

    import React from "react";
    import { useChat } from "@nlxchat/react";
    
    const ChatWidget = () => {
      const chat = useChat({
        botUrl: ""
      });
    
      return (
        <div>
          {chat.responses.map(/* render messages in the current conversation */)}
        </div>
      );
    };

    The API of the hook is similar to the vanilla API. It leaves out subscribe and unsubscribe methods as they are used internally in effect hooks, making sure things are properly cleaned up. Instead, messages are readily available in the chat.messages field, and we added state hooks for taking care of the value of the chat input field. You are free to not use these and manage things on your own.

    See the standalone chat widget implemention for a production-grade example.

    License

    MIT.

    Keywords

    none

    Install

    npm i @nlxchat/react

    DownloadsWeekly Downloads

    19

    Version

    0.5.1

    License

    MIT

    Unpacked Size

    11.3 kB

    Total Files

    6

    Last publish

    Collaborators

    • nlxai