Skip to content

Access store outside components #2671

Answered by HungDang2911
HungDang2911 asked this question in Q&A
Discussion options

You must be logged in to vote

Here is my code

//UserStore.ts

import { Instance, types, flow, applySnapshot } from "mobx-state-tree"
import { login, register } from "../services/api/authAPI"
import { withEnvironment } from "./extensions/with-environment"

export const defaults = {
  _id: "",
  username: "",
  accessToken: "",
  refreshToken: "",
}

export const UserStoreModel = types
  .model()
  .props({
    _id: types.string,
    username: types.string,
    accessToken: types.string,
    refreshToken: types.string,
  })
  .extend(withEnvironment)
  .actions((self) => ({
    login: flow(function* (account) {
      const { accessToken, refreshToken } = (yield login(account)).data
      console.tron.log(accessToken, ref…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@HungDang2911
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@danielkcz
Comment options

@mweststrate
Comment options

Answer selected by danielkcz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants