FredrikOseberg / react-chatbot-kit

MIT License
324 stars 154 forks source link

Typescript example? #150

Open slikk66 opened 1 year ago

slikk66 commented 1 year ago

Hi, new user - Having issues with the Widgets using Typescript. Keeps complaining that it doesn't like this construct for "widgetFunc" in TS:

     widgets: [
        {
            widgetName: "widgetOptions",
            widgetFunc: (props) => <WidgetOptions {...props} />,
        },
    ],

All examples I've seen are in JS, is there any full TS example out there? After trying to fix things up myself, keep getting into more Type errors.

Thanks!

slikk66 commented 1 year ago

This seems to work, if you rename the config file to .tsx (not .ts)

    import { createChatBotMessage } from "react-chatbot-kit";
    import WidgetOptions from "./components/WidgetOptions";

    import IConfig from "react-chatbot-kit/build/src/interfaces/IConfig";

    export const config: IConfig = {
        initialMessages: [
            createChatBotMessage(`Welcome to our bot!`, {}),
            createChatBotMessage(`Would you like to continue?`, {
                widget: "widgetOptions",
                delay: 2000,
            }),
        ],
        widgets: [
            {
                widgetName: "widgetOptions",
                props: {},
                mapStateToProps: [],
                widgetFunc: (props) => <WidgetOptions {...props} />,
            },
        ],
    };