https://github.com/shallinta/vue3-hooks
Using vue3.x composition api in react-hooks style. Implemented just with composition api.
https://github.com/shallinta/vue3-hooks
composition-api react-hooks reactive ref useeffect usestate vue vue-hooks vue3 vue3-hooks
Last synced: 21 days ago
JSON representation
Using vue3.x composition api in react-hooks style. Implemented just with composition api.
- Host: GitHub
- URL: https://github.com/shallinta/vue3-hooks
- Owner: shallinta
- License: mit
- Created: 2020-05-28T02:46:31.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-03-26T19:21:43.000Z (about 3 years ago)
- Last Synced: 2025-03-29T15:11:20.926Z (about 2 months ago)
- Topics: composition-api, react-hooks, reactive, ref, useeffect, usestate, vue, vue-hooks, vue3, vue3-hooks
- Language: TypeScript
- Size: 249 KB
- Stars: 14
- Watchers: 1
- Forks: 1
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Vue3 hooks
[](https://www.npmjs.org/package/vue3-hooks)
[](https://www.npmjs.org/package/vue3-hooks)
[](https://github.com/shallinta/vue3-hooks/blob/master/LICENSE)
[](https://github.com/shallinta/vue3-hooks/issues?q=is%3Aopen+is%3Aissue)
[](https://github.com/shallinta/vue3-hooks/issues?q=is%3Aissue+is%3Aclosed)

[](https://github.com/shallinta/vue3-hooks)[](https://www.npmjs.com/package/vue3-hooks)
> Using vue3.x composition api in react-hooks style.
The react-like vue3 hooks are implemented just with composition api, requiring no any other dependencies but vue3.
If you are used to react hooks, and new to vue 3, you will try this. In this case, however, I suggest learning original composition api. It's easy :D.
What `vue3-hooks` really make sense is that so many third-party hooks library based on react can now easily migrate to vue technolegy stack.
If you are an author of third-party react hooks, you may consider to use `vue3-hooks` to migrate your library to vue family. Very few code modification is required.## install
```sh
npm install --save vue3-hooks
```## features
- [x] useState (use `ref` and `reactive` from vue)
- [x] useEffect (use `watch` from vue)
- [ ] *WIP*: more react-like hooks> `useCallback` is no need because `setup` will only been run once.
## usage
```javascript
import { computed } from 'vue';
import { useState, useEffect } from 'vue3-hooks';
import ajaxFetch from 'ajax-fetch-esm';
// ...{{ id }}
Counter: {{ count }}
{{ data.toString() }}
// ...
setup(props) {
// ...// all vue apps prefer using counter for example instead of hello world.
const [count, setCount] = useState(0);
const [data, setData] = useState({});// yes, vue3 composition api allow us passing an async function.
// normal functions are also ok.
// `() => props.id` means watching a computed vue3 variable.
useEffect(async ([nextCount, nextId], [prevCount, prevId]) => {
const timer = setTimeout(() => {
setData(await ajaxFetch.get({ current: nextCount, id: nextId }));
}, 500);
// clean up
return () => {
clearTimeout(timer);
};
}, [count, () => props.id]);// ...
return {
// ...
count,
data,
id: computed(() => props.id),
// ...
};
}
// ...```
## Recently updated
See [CHANGELOG](CHANGELOG.md) here.
## LICENSE
[MIT](LICENSE)