question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pinia state undefined in vue dev tools

See original GitHub issue

Reproduction

Yes

Steps to reproduce the bug

Defined store with following:

import { defineStore } from 'pinia';

export const useUsersStore = defineStore({
  id: 'user',
  state: (): UserState => ({
    user: {} as User,
  }),
  getters: {
    token: (state) => state.user.token,
  },
  actions: {
    async addUserToken(token: string | null) {
      this.user = { token: token };
    },
  },
});

Access the store in component

const usersStore = useUsersStore();
const { user } = storeToRefs(usersStore);

Open dev tools

Expected behavior

I expect the store state to be visible in the dev tools.

Actual behavior

image

The _custom object contains the values, however it doesn’t look like it works as expected.

Additional information

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
CreativeWarlockcommented, Jul 16, 2022

On a side note, the property of a state also becomes undefined when you a) use a getter method has the same name as one of the props defined in the state, b) use async modifier at the state definition, like so: async state: () => { let userId = await axios.get('urlToMyFancyUserService') return { id: userId } },

0reactions
bartduisterscommented, Jul 24, 2022

@posva The reproduction is posted in my previous comment. Is it sufficient?

Read more comments on GitHub >

github_iconTop Results From Across the Web

vue.js - Vue3.js and Pinia: Why is my store state undefined in ...
I found a away to solve it, though I think its not perfect // should use computed const languages = computed(() => languageStore.languages ......
Read more >
State | Pinia
The state is, most of the time, the central part of your store. People often start by defining the state that represents their...
Read more >
"Cannot read properties of undefined" error in simple pinia store.
Getting a "Cannot read properties of undefined (reading settings)" error in the console. Not sure why. The getter if working just fine.
Read more >
Complex Vue 3 state management made easy with Pinia
Build a basic blog engine using Pinia, a state management tool for Vue apps, and its main features, including state, getters, and actions....
Read more >
Why is Vue DevTools displaying Pinia getters like this?
To cut to the chase, if I look under "computed" in Vue DevTools for store ... the in the Pinia tab of DevTools,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found