Skip to content

Idea: Access state without the need of useGetters #10

@l-portet

Description

@l-portet

First, thanks for the great package :)

What about a hook to access the state directly instead of having to write a specific getter, such as mapState in VueX?
I find it a bit redundant to write getters for each property of my state.

Example:

// store.js
const store = {
  state: { count: 0 },
  mutations: {
    SET_COUNT(state, value) {
      state.count = value;
    }
  },
  actions: {
    increment(context) {
      context.mutations.SET_COUNT(context.state.count + 1);
    }
  }
}
import { useStoreState } from 'vuex-but-for-react';

export function Counter() {
  const count = useStoreState('count');
  // or const count = useStoreState(state => state.count);

  return //...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions