Questions tagged [mobx-react-lite]

43 questions
8
votes
1 answer

What exactly does mobx-react-lite's "useLocalStore" hook do, and why is it (only sometimes) needed?

Within the mobx-react documentation there are variations in how stores are created. For example, on the React Context page: In the first code sample, the store is instantiated with useLocalStore: const store = useLocalStore(createStore) In the…
arhnee
  • 715
  • 5
  • 19
7
votes
1 answer

MobX: Since strict-mode is enabled, changing (observed) observable values without using an action is not allowed

My context looks like this: class AuthStoreClass { authUser = null constructor() { makeAutoObservable(this) } login = async (params) => { const { data: { data: authUser } } = await loginUser(params) …
mleister
  • 443
  • 8
  • 23
5
votes
1 answer

Shouldn't useContext() only be used for low frequent updates? (mobx-react-lite)

Almost all examples (even the official documentation) use mobx-react-light in combination with useContext() hook. However, React, many articles and blog-posts advice to NOT USE useContext() for middle/high frequent updates. Isn't state something…
mleister
  • 443
  • 8
  • 23
2
votes
1 answer

Mobx / React update issue

I'm just learning Mobx and I'm trying to get this component to update with no luck. It seems like it should update, it just doesn't. What am I missing? 'use strict'; const observer = mobxReact.observer; const makeAutoObservable =…
MPT
  • 173
  • 8
2
votes
0 answers

Attempted import error: 'makeObservable' is not exported from 'mobx'

import React from 'react' import { observer } from 'mobx-react'; //Cause of Error export default observer(App); //At the bottom of the code the only line causing an error is import { observer } from 'mobx-react'; and gives my the following…
aneuroo
  • 19
  • 4
2
votes
1 answer

React Navigation 5 authentication flow with MST, not "switching"

So, I've just upgraded an ignite-bowser project to their 5.0 template, which includes React Navigation 5, which requires a change from the legacy recommended method of using a SwitchNavigator to swap between 'Auth' and 'App' StackNavigators, to a…
2
votes
1 answer

MobX with React best practice with observer

I'm not really facing an issue, it's more like I'm wondering what is the best way I should use mobx with react. So here's my situation: I'am fairly new to mobx but I've got years of experience using react (mostly with redux). My new project is using…
1
vote
1 answer

Observer does not work for recursive items

I'm really stuck with the problem. I have a nested menu. After click on the first menu level second level items shows up. After click on one of the children nothing happens. Looks like the observer don't work for deep levels items. I don't know if…
1
vote
0 answers

MobX class store vs functional store

What is the difference between Mobx 6 class store vs functional store? class store export class UserStore { username; role; constructor() { makeAutoObservable(this) } } function store const store = useLocalObservable(() =>…
s1n7ax
  • 1,567
  • 4
  • 16
  • 32
1
vote
0 answers

Usage of mobx in custom react hooks

We're using custom hooks in our app to invoke automatic analytics/general hooks which using const user = useObserver(() => userStore.user); to dispatch analytics (lifecycles of components/general usages) But I have seen that useObserver hook of mobx…
1
vote
1 answer

Why can't we use React.useMemo in mobx-react to keep reference to the state object?

Currently my project is still using mobx@4 and mobx-react@6 and I found this warning in the documentation: Fair warning. Don't ever use React.useMemo to keep reference to the state object. It may be randomly thrown away by React and you may lose…
1
vote
1 answer

Fowarding a ref with mobx

i am trying to build a custom component video player with react and mobx, and i need to drill a refrence from a main component to a child Component but i'm getting an error message when i use the forwardRef function on a component that is an…
DBankx
  • 113
  • 9
1
vote
0 answers

MobX-state-tree store is not appearing in props

I am implementing MobX-state-tree into my React Native app using MobX-react-lite. I am able to access the store directly using a hook I wrote from a tutorial I found: const useInject = (mapStore: MapStore) => { const store = useStore(); …
Tristan
  • 152
  • 13
1
vote
1 answer

How to make child component reactive to state change in mobx using mobx-react-lite

I'm using mobx-state-tree and mobx-react-lite, can someone guide me to a better pattern, wishlist.js - wishlist store import { types } from 'mobx-state-tree' export const WishListItem = types.model('WishListItem', { name: types.string, price:…
AviKKi
  • 770
  • 5
  • 13
1
vote
1 answer

Testing mobx react observer with react usecontext - React, Mobx

New to testing mobx with React. I'm testing a a simple side navigation bar, open/closes on hamburger menu. I have set up a store for the Navbar: export class Store { toggle = false; setToggle(bool){ this.toggle = bool; …
medev21
  • 1,502
  • 3
  • 22
  • 36
1
2 3