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

0.9.5 • Public • Published

Chat Headless React

Chat Headless React is the official React UI Bindings layer for Chat Headless

Full Documentation

Getting Started - ChatHeadlessProvider

Chat Headless React includes an <ChatHeadlessProvider /> component, which takes in a ChatConfig, instantiate a ChatHeadless instance and makes it available to the rest of your app:

import { ChatHeadlessProvider, ChatConfig } from "@yext/chat-headless-react";

const config: ChatConfig = {
  botId: "BOT_ID",
  apiKey: "API_KEY",
};

function MyApp() {
  return (
    <ChatHeadlessProvider config={config}>
      {/* Add components that use Chat as children */}
      <MyComponent />
    </ChatHeadlessProvider>
  );
}

Respond to State Updates with useChatState

useChatState reads a value from the ChatState state and subscribes to updates.

import { useChatState } from "@yext/chat-headless-react";

export default function MyComponent() {
  const isLoadingStatus = useChatState((state) => state.conversation.isLoading);
  return <div>{`Loading Status: ${isLoadingStatus}`}</div>;
}

Dispatch Actions with useChatActions

useChatActions allows you to dispatch actions using the ChatHeadless instance.

import { useChatActions } from "@yext/chat-headless-react";
import { useCallback } from "react";

function MyComponent() {
  const actions = useChatActions();
  const onClick = useCallback(() => {
    actions.setChatLoadingStatus(true);
  }, [actions]);

  return <button onClick={onClick}>Click Me</button>;
}

Package Sidebar

Install

npm i @yext/chat-headless-react

Weekly Downloads

232

Version

0.9.5

License

BSD-3-Clause

Unpacked Size

85.5 kB

Total Files

64

Last publish

Collaborators

  • jaredhood
  • jrhoads
  • apavlick
  • ejaffee1
  • ttanushree
  • yext_eng_npm
  • benmcginnis
  • kunal-p
  • tmeyer2115
  • mbowman
  • jronkin_yext
  • ataing
  • svc_jenkins_consulting_yext
  • cblair_yext
  • emilyfranklin
  • willgorick
  • bhaines-yext
  • mkouzel
  • rconsalo
  • jknutsonn
  • tritpham
  • sharvey
  • npatel94
  • alapre
  • johncho92
  • canderson_yext
  • ssaunders
  • rpope
  • eal172
  • peteros
  • ytruong
  • mkilpatrick
  • baigel1
  • ajgist
  • jballschneider
  • eefi
  • pmomesso
  • dkang3021
  • mleifer
  • lymarrie
  • tobyko
  • jfromm
  • dsurducan
  • dgurland
  • zhengzhi
  • slapshot-bot
  • petya182
  • paigep
  • htamirepi
  • dlsgusrn7577
  • bryanreed
  • lilwang
  • afriedman00
  • sre-ops
  • scheerla
  • a_ashwik
  • bajohnson-yext
  • saivythik
  • tarun-revalla-yext
  • manash-rauta
  • gargsi
  • souravkumar
  • yext-bot
  • anguyenyext
  • tsayyapureddi
  • johnnguyen
  • tpotla
  • nbramblett
  • rpope-yext
  • deepakyext
  • sahilvaidya
  • mgdunn2
  • kgerner-yext
  • fondriest
  • sscott24
  • emilyzhang777
  • karthik-surya-yext
  • jgomezy
  • gonzalo-novak
  • mauriciohr-yext
  • lwyattyext
  • qciccoretti