Questions tagged [mobx-react-lite]

67 questions
28
votes
3 answers

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
  • 1,697
  • 2
  • 20
  • 46
12
votes
3 answers

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
  • 1,044
  • 9
  • 24
6
votes
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…
user13468285
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
  • 1,697
  • 2
  • 20
  • 46
4
votes
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…
4
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…
3
votes
0 answers

Invariant Violation: No callback found with cbID 3902 and callID 1951 for module

I'm creating a library of React Native components. On my library I have this simple component import React from 'react' import {View, Text } from 'react-native' export default function App() { return Hello
3
votes
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
  • 2,469
  • 8
  • 31
  • 43
3
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…
2
votes
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…
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
  • 183
  • 8
2
votes
2 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
  • 77
  • 1
  • 8
1
vote
2 answers

is it possible to call a MobxStateTree action from a child model?

I create a Mobx State Tree global state composed by a DataModel that contains a TranslationsDataModel. In DataModel I created a fetchDataset function that I would like to call in TranslationsDataModel but I get an error saying that fetchDataset is…
whitecircle
  • 237
  • 9
  • 34
1
vote
0 answers

Mobx/React Native: Component not updating on state change

I'm trying to create a simple React-Native MobX example-here's the working web example here // App.tsx const apiGetItems = async () => { return await new Promise(resolve => { resolve([ {id: 1, title: 'eggs', quantity: 10}, {id: 2,…
Kearney Taaffe
  • 647
  • 8
  • 20
1
vote
2 answers

React - Pass JSX / React component to "unrelated" component

I'm looking for a flexible approach that will allow me to send some JSX to a totally unrelated component. For example, a modal. Let's assume we have some boilerplate code for a global store and we can access it from any component with a custom…
1
2 3 4 5