1.0.15 • Published 11 months ago

react-ai-assistant v1.0.15

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

How to use this library

Use AssistantProvider to wrap your components in your App.tsx

<AssistantProvider>
    <Routes>
    ...
    </Routes>
</AssistantProvider>

In your home component use the setNavigationCallback to tell AssistantProvider how to navigate to a page

const Home = (props: Props) => {
  const navigate = useNavigate();

  useEffect(() => {
    setNavigationCallback(path => {
      navigate(path);
    });
  }, [navigate]);

  ...

Based on your automations use the useAssistedRef and useAssistedState

For example:

consider you have automations:

export const automations : {[key: string]: automation} = {
  "create-project": {
    "steps": [
      {
        type: "goto",
        path: "/project"
      },
      {
        type: "state",
        id: "create-project-name",
        value: 0,
        varRef: [
          "name"
        ]
      },
      {
        type: "state",
        id: "create-project-descr",
        value: 0,
        varRef: [
          "descr"
        ]
      },
      {
        type: "state",
        id: "create-project-repo",
        value: 0,
        varRef: [
          "repo"
        ]
      },
      {
        type: "click",
        id: "create-project",
        be_careful: true
      }
    ],
  }

An automation step of type state has to be attached to your state in your component of choice like this:

...

const [name, setName] = useAssistedState("create-project-name", "");

...

return (
    ...

    <InputWithValidation
        label='Project name'
        placeholder='name of your project'
        value={name}
    />

    ...
);

An automation step of type click has to be attached using a ref like this:

...

const ref = useAssistedRef("create-project");

...

return (
    ...

    <button onClick={() => setIsOpen(true)} className='btn' ref={ref}>
        Create Project
    </button>

    ...
)
1.0.15

11 months ago

1.0.14

11 months ago

1.0.13

11 months ago

1.0.12

11 months ago

1.0.11

11 months ago

1.0.10

11 months ago

1.0.9

11 months ago

1.0.8

11 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago