greenpress / vuex-composition-helpers

A util package to use Vuex with Composition API easily.
https://www.npmjs.com/package/vuex-composition-helpers
MIT License
288 stars 32 forks source link

Possible to directly access a nested value inside of the state? #77

Closed Fenrir200678 closed 1 year ago

Fenrir200678 commented 1 year ago

Hi, I'm using Vue 3 (v3.2.37)with Vuex 4 (v4.0.2) and the vuex-compositio-helpers v.2.0.3 and am wondering if it is somehow possible to access a nested value in the state directly via the useState helper? E.g. I want to access only the user.token not the whole user object. In this case it's just an example, but I have API responses with huge nested objects in my state and don't want to map that whole object if I just need 1 or 2 values from it.

export default createStore({
  state: {
    user: {
      token: '12345',
      first_name: 'foo',
      last_name: 'bar'
    }
  },
...
})

In my component I tried several things without luck. Like this:

import { useState } from 'vuex-composition-helpers/dist'

const { token } = useState({ token: (state) => state.user.token })
const { token } = useState(['user/token'])
const { token } = useState(['user.token'])

Any possibility to get this done or is a feature like that planned?

davidmeirlevy commented 1 year ago

hi!

thanks for this issue. that's a new room for new bugs and intellisense issues, so I don't believe we should add this kind of feature.

Fenrir200678 commented 1 year ago

Too bad, but thanks for the quick response! :)

davidmeirlevy commented 1 year ago

no problem.

if you're looking to contribute something in the hackroberfest, go to: https://github.com/greenpress/microf