1.0.15 • Published 2 years ago

react-ai-assistant v1.0.15

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years 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

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago