GithubHelp home page GithubHelp logo

u3u / vue-hooks Goto Github PK

View Code? Open in Web Editor NEW
491.0 10.0 34.0 2.59 MB

⚡️Awesome Vue Hooks

Home Page: https://vue-hooks.netlify.com

License: MIT License

JavaScript 4.62% TypeScript 92.14% CSS 3.24%
vue vue-use vue-hooks vue-function-api vue-composition-api

vue-hooks's Introduction

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

vue-hooks's People

Contributors

dependabot-preview[bot] avatar pochodaydayup avatar semantic-release-bot avatar u3u avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-hooks's Issues

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

Example of useState

Hi! Thanks for your code. Is it possible to have an example of usage of the useState hook?

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

build fail due to duplication with dayjs

Hi there. First thanks for this nice package. We are using it for the vuex bindings only though, and the added stuff is creating some problems:

ERROR in /var/www/yoda/node_modules/@u3u/vue-hooks/node_modules/dayjs/locale/index.d.ts(10,12):

10:12 Duplicate identifier 'locale'.

     8 |   const locale: locale.Locale

     9 | 

  > 10 |   export = locale

       |            ^

    11 | }

    12 | 



 error  in /var/www/yoda/node_modules/dayjs/locale/index.d.ts



ERROR in /var/www/yoda/node_modules/dayjs/locale/index.d.ts(10,12):

10:12 Duplicate identifier 'locale'.

     8 |   const locale: locale.Locale

     9 | 

  > 10 |   export = locale

       |            ^

    11 | }

    12 | 

I'd suggest moving dayjs into a peer dependency, or completely removing this hook from the package - after all, users might use a different library or a native implementation etc.

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

support for vue 2.7

hi! i'm using your library for a long time. i've a vue2 large application which I am going to port first to vue 2.7 (naruto) and then hopefully to vue3. as vue2.7 embed the vue-composition-api functionalities, i'll remove it from the project. but because of this you library is no longer working. i'm just using three hooks: useState, useRouter and useMutations. how do you recommend to proceed to update your library? any help is much appreciated!

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

remove dayjs dependency

this would be a very useful package if it didn't force my project to install and include dayjs in my bundle

would appreciate if you remove the dependency I think I fork and and remove the date hook and reference this repo

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

Getter does not accept payload

Hello, I am trying to send a payload through the Getter but it sends me an error in the console where it tells me that it is not a function. How could I send a payload to filter store data please.

As follows
getters.myGetter("filter")

How can we mount components with vue-hooks in unit test

Hi, great thanks for this amazing project!

I tried to unit test my component with vue-hooks using vue-test-utils. When I mount my component, I got [vue-hooks] Not found vue instance error. I think I need a mock regarding vuex to do it, but I have no clue how to do so. Could you please guide us how we can provide a mocked hooks in order to unit test components based on them? Thanks a lot.

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

vue-function-api + Vue-hooks + spread operator examples

Configuring our setup()
It is a good idea to identify each logical part of the setup component. For this we can take as reference the structure of the store, where we have separated the state , mutations, actions,
getters
...

As you know, Vuex uses a single state tree, that is, this single object contains all its application level status and serves as the "single source of truth." This also means that you will usually only have one store for each application. A single status tree facilitates the location of a specific state and allows us to take snapshots of the current state of the application for debugging purposes.

We can conclude that we can maintain the concept of single state tree, which will help us understand our code logic as the project grows.

What is the spread operator?
The spread operator allows an expression to be expanded in situations where multiple arguments (function calls) or multiple elements (literal arrays) are expected.

<script>
  import {onCreated} from 'vue-function-api';
  import {useState , useActions} from '@u3u/vue-hooks'

  export default {
    setup(){
      const state = { 
        ...useState(['items' , 'isLoading'])
      }
      const actions = { 
        ...useActions(['GET_ITEMS'])
      };
      onCreated(() =>{
        actions.GET_ITEMS();
      });

      return{
        items: state.items,
        isLoading: state.isLoading
      }  
    },
  };
</script>

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

Add generic support to vuex hooks

Hello,

I've recently started to use vue-hooks for vuex. I've noticed that when creating a reactive state variable that expanding out useGetters returns an untyped dictionary. This causes typing issues in TS if you also have regular values as well. It can be overcome by first casting to unknown and then your type. I've noticed this also applies to the other vuex hooks. Would it be possible to support generics on the hooks to reduce the boilerplate?

const state = reactive({
            owner: '',
            ...useGetters(ProfileNS,[
              nameof<ProfileGetters>(x => x.picture),
              nameof<ProfileGetters>(x => x.name),
            ]) as unknown as { picture: string, name: string },

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

features request: when to get Vuex instance

Now get VM with beforeCreate hooks, so the hooks only work in vue constructor.
But like Vuex, we often use outside the Vue component. Maybe we should give an interface to pass Vuex instance when using it outside the Vue component.

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

Dependabot can't resolve your JavaScript dependency files

Dependabot can't resolve your JavaScript dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Error whilst updating @types/storybook__vue in /yarn.lock:
Couldn't find package "storybook__vue@*" required by "@types/[email protected]" on the "npm" registry.

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.