@jgamaraalv/react-auto-complete
Version:
An amazing auto complete for your React application
101 lines (73 loc) • 1.93 kB
Markdown
An awesome `Auto Complete` for your React application.
```
yarn add @jgamaraalv/react-auto-complete
npm install @jgamaraalv/react-auto-complete
```
First, you need to clone the repository
```
git clone https://github.com/jgamaraalv/react-auto-complete react-auto-complete
```
Then you can run
```
yarn install
yarn dev
yarn test:unit
npm install
npm dev
npm test:unit
```
You can use the pre compounded component like the example below
```jsx
import Autocomplete from "@jgamaraalv/react-auto-complete";
// if you are running locally
// import { Autocomplete } from "./components/Autocomplete";
function App() {
const { run, data } = useAsync<PromiseType<ReturnType<typeof products>>>();
useEffect(() => {
run(products());
}, []);
async function searchProductHandler(
event: React.ChangeEvent<HTMLInputElement>
) {
run(products(event.target.value));
}
return (
<div>
<Autocomplete options={data} onSearch={searchProductHandler} onOptionSelected={(selectedValue) => console.log(selectedValue)} />
</div>
);
}
export default App;
```
Or you can compound by yourself
```jsx
import { Autocomplete } from "@jgamaraalv/react-auto-complete";
// if you are running locally
// import { Autocomplete } from "./components/Autocomplete";
function App() {
return (
<div>
<Autocomplete>
<Autocomplete.Input placeholder="Input value" />
<Autocomplete.List>
<Autocomplete.ListItem value="value1">Value 1</Autocomplete.ListItem>
<Autocomplete.ListItem value="value2">Value 2</Autocomplete.ListItem>
</Autocomplete.List>
</Autocomplete>
</div>
);
}
export default App;
```