Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
React Native: use mobx store state from another store

I was wondering how can I use a n observable from one store inside another store class, for example use userStore inside mapStore.

Now I will show you how I initiate stores and use them in my functional components:

/contexts/index.js

import React from 'react'
import { configure } from 'mobx';
import { UserStore }  from '../stores/UserStore.js'
import { MapStore }  from '../stores/MapStore.js'

export const storesContext = React.createContext({
    userStore: new UserStore(),
    mapStore: new MapStore(),
});

configure({ enforceActions: "observed" });

/hooks/use-stores.js

//hooks/use-stores.js

import React from 'react'
import { storesContext } from '../contexts/index.js'

export const useStores = () => React.useContext(storesContext);

Inside my functional components I access like this:

import { useStores } from '@hooks/use-stores';
...
const { mapStore,userStore } = useStores();

An example class, UserStore

export class UserStore
{
    constructor()
    {
        makeAutoObservable(this);
user = false;

}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!