Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@u3u/vue-hooks

u3u508MIT2.0.1TypeScript support: included

⚡️ Awesome Vue Hooks

vue, vue-use, vue-hooks, vue-function-api, vue-composition-api

readme

vue-hooks NPM Version Build Status Code Coverage

⚡️ Awesome Vue Hooks

Using @vue/composition-api to implement useful vue hooks.
Vue 3.0 has not been released yet, it allows you to use functional-based components in advance.

⚠️ 2.x has been switched to @vue/composition-api, if you are using version 1.x please use vue-function-api

Install

yarn add @vue/composition-api @u3u/vue-hooks

Documentation Netlify Status

Docs are available at https://vue-hooks.netlify.com

Usage

Edit Vue Hooks Examples

import Vue from 'vue';
import VueCompositionAPI from '@vue/composition-api';
import hooks from '@u3u/vue-hooks';

Vue.use(hooks);
Vue.use(VueCompositionAPI); // Don't forget to use the plugin!
import { createComponent } from '@vue/composition-api';
import { useWindowSize } from '@u3u/vue-hooks';

export default createComponent({
  setup() {
    const { width, height, widthPixel, heightPixel } = useWindowSize();
    return { width, height, widthPixel, heightPixel };
  },

  render() {
    const { width, height, widthPixel, heightPixel } = this;
    return (
      <div id="app" style={{ width: widthPixel, height: heightPixel }}>
        dynamic window size: {width}, {height}
      </div>
    );
  },
});

Hooks

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b feat/new-hook
  3. Commit your changes: git commit -am 'feat(hooks): add a new hook'
  4. Push to the branch: git push origin feat/new-hook
  5. Submit a pull request :D

Contributors

Thanks goes to these wonderful people (emoji key):

u3u
u3u

💻 📖 💡 ⚠️

This project follows the all-contributors specification. Contributions of any kind are welcome!

License

MIT

changelog

2.0.1 (2019-08-25)

Bug Fixes

  • release: semantic release (c5d2ee8)

1.4.0 (2019-08-16)

Bug Fixes

  • deps: move to dev dependencies (8a64b14)

Features

  • hooks: add useMedia hook (dee851e)

1.3.0 (2019-08-07)

Bug Fixes

  • hooks: fix usePrevious does not work when passing state (8567a04)

Features

  • hooks: add useTimeout hook (61db981)

1.2.0 (2019-08-06)

Features

  • hooks: add useMountedState hook (1e70d5e)
  • hooks: add useRef hook (f600ab8)

1.1.1 (2019-07-26)

Bug Fixes

  • ts: forgot to export the type definition file (5cb25ec)

1.1.0 (2019-07-18)

Bug Fixes

  • hooks: vm.$router should not be computed wrapper (8483d43)

Features

  • hooks: add usePrevious hook (f4d0dc8)

1.0.0 (2019-07-17)

Bug Fixes

  • hooks: improve vuex interface (fdae9b1)
  • hooks: improve vuex interface again (87bd2a5)
  • hooks: using runtime plugin (e0f556d)
  • util: vm must have a setup function (d6ffe8b)

Features

  • hooks: add useActions hook (1106ade)
  • hooks: add useCounter hook (200086e)
  • hooks: add useGetters hook (49376cb)
  • hooks: add useMutations hook (b38358c)
  • hooks: add useRouter hook (df8bdda)
  • hooks: add useState hook (607dfd1)
  • hooks: add useStore hook (109995a)
  • hooks: export hooks in entry (3f0d5dd)
  • util: add vue runtime (f7ff827)