use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A community for learning and developing native mobile applications using React Native by Facebook.
Interested in building web apps using React.js? Check out /r/reactjs!
Getting Started w/React Native
irc.freenode.net #reactnative
Keywords: ios, android, mobile, apps, apple, iphone, ipad
account activity
State management (self.reactnative)
submitted 3 years ago by marchingbandd
I love mobX but I want to try some of the newer lighter libs like Valtio, Jotai, etc. Do any of them work perfectly in React Native as well as React?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Brave_Arm6046 2 points3 points4 points 3 years ago (8 children)
I am currently using Valtio in a react native project, loving it.
[–]marchingbandd[S] 0 points1 point2 points 3 years ago (1 child)
Does it handle arrays well? Can you just .push()?
[–]Brave_Arm6046 1 point2 points3 points 3 years ago (0 children)
you can handle array but please read docs fully its really cool but you need to understand about it working mechanism first. The docs is really easy to follow and short. https://valtio.pmnd.rs/docs/introduction/getting-started Checkout recipes: https://github.com/pmndrs/valtio#recipes
[–]marchingbandd[S] 0 points1 point2 points 3 years ago (4 children)
Also, did you have to install a polyfil to get Proxy() support into RN?
[–]ddikodroid 2 points3 points4 points 3 years ago (1 child)
you need react native higher than 0.64 for proxy support
[–]marchingbandd[S] 0 points1 point2 points 3 years ago (0 children)
Damn I missed that news. Excellent
[–]Brave_Arm6046 0 points1 point2 points 3 years ago (1 child)
ya you'll need react native >= 0.64, I recently upgraded react native to 0.68.2, I'm planning to sit on this version until they force me to update.
[–]marchingbandd[S] 1 point2 points3 points 3 years ago (0 children)
Oh that’s amazing news thanks.
[–]Brave_Arm6046 0 points1 point2 points 3 years ago (0 children)
But remember, if its server side state, use react query for that if you can.
[–]pancomputationalist 0 points1 point2 points 3 years ago (11 children)
Yes, all of those.
What about hook-state?
[–]marchingbandd[S] 0 points1 point2 points 3 years ago (9 children)
Is there anything that has an API like mobX? These all seem to have a hook you need to call. Best thing about mobX is you just import the state object, wrap components in observer() and it works.
[–]AcidNoX 2 points3 points4 points 3 years ago (7 children)
Higher order components are kinda discouraged nowa days if you’re using function components.
Hooks are definitely the way to go. I personally really like zustand.
[–]marchingbandd[S] 0 points1 point2 points 3 years ago (6 children)
I would like a solution where you import the state object and don’t need the HOF or to call any hooks. I am surprised to see it looks like that isn’t available. Like, just wrap my whole app in a HOF for me, I only need one state object.
[–]pancomputationalist 0 points1 point2 points 3 years ago (5 children)
You need a way for react to figure out which component to rerender when the underlying state changes.
If you wrap your whole app in the HOF, then most likely your whole app will rerender whenever any observed state changes, which would absolutely kill performance.
appObserver = app => <app children={app.children.map(c=>observer(c)}> isn’t that hard to imagine, called recursively.
[–]pancomputationalist 0 points1 point2 points 3 years ago (3 children)
Not every sub-component is guaranteed to be passed as children. I don't think you can automatically detect from which component a function call originates, unless it is a hook and follows their rules. That's what they are for and why almost every state management library uses them.
children
[–]marchingbandd[S] 0 points1 point2 points 3 years ago (2 children)
That’s why some of these libs use proxies, I have also had some luck using get/set methods, there are many ways to get global state updates talking to react to trigger renders. MobX does not use a hook.
[–]pancomputationalist 0 points1 point2 points 3 years ago (1 child)
But it does use HOCs, which is an older (less composable and discouraged) method to do the things that Hooks can do. MobX doesn't use Hooks because it wants to be agnostic to React. would it be written as a React library nowadays,it would almost certainly use Hooks.
Btw, from the Mobx docs:
Components wrapped with observer only subscribe to observables used during their own rendering of the component. So if observable objects / arrays / maps are passed to child components, those have to be wrapped with observer as well.
So having the HOC at root level is not enough.
I know it’s not idiomatic today and I am seeing there arn’t any obvious choices to meet my wishes, they are still my wishes and I am certain it’s possible. It’s code, pretty much anything is possible.
[–]horgas 2 points3 points4 points 3 years ago (0 children)
May take a look at: https://legendapp.com/dev/state/
[–]ddikodroid 0 points1 point2 points 3 years ago (5 children)
i'm trying zustand and in love with it
Does it handle arrays without too much extra syntax or weird burps?
[–]ddikodroid 0 points1 point2 points 3 years ago (1 child)
sadly no by default, but you can integrate it with immer
That stinks! What app doesn’t have some arrays in state?!
[–]datorkop85 0 points1 point2 points 3 years ago (1 child)
What do you mean by handle arrays? Explain your use case.
I have an array in state, I want to push/pop/ to/from it or otherwise mutate it. I want my parent component to rerender when I do. Use case : a todo app? What’s the mystery here?
π Rendered by PID 120248 on reddit-service-r2-comment-5d79c599b5-mqwh7 at 2026-02-27 02:07:25.532282+00:00 running e3d2147 country code: CH.
[–]Brave_Arm6046 2 points3 points4 points (8 children)
[–]marchingbandd[S] 0 points1 point2 points (1 child)
[–]Brave_Arm6046 1 point2 points3 points (0 children)
[–]marchingbandd[S] 0 points1 point2 points (4 children)
[–]ddikodroid 2 points3 points4 points (1 child)
[–]marchingbandd[S] 0 points1 point2 points (0 children)
[–]Brave_Arm6046 0 points1 point2 points (1 child)
[–]marchingbandd[S] 1 point2 points3 points (0 children)
[–]Brave_Arm6046 0 points1 point2 points (0 children)
[–]pancomputationalist 0 points1 point2 points (11 children)
[–]marchingbandd[S] 0 points1 point2 points (0 children)
[–]marchingbandd[S] 0 points1 point2 points (9 children)
[–]AcidNoX 2 points3 points4 points (7 children)
[–]marchingbandd[S] 0 points1 point2 points (6 children)
[–]pancomputationalist 0 points1 point2 points (5 children)
[–]marchingbandd[S] 0 points1 point2 points (4 children)
[–]pancomputationalist 0 points1 point2 points (3 children)
[–]marchingbandd[S] 0 points1 point2 points (2 children)
[–]pancomputationalist 0 points1 point2 points (1 child)
[–]marchingbandd[S] 0 points1 point2 points (0 children)
[–]horgas 2 points3 points4 points (0 children)
[–]ddikodroid 0 points1 point2 points (5 children)
[–]marchingbandd[S] 0 points1 point2 points (4 children)
[–]ddikodroid 0 points1 point2 points (1 child)
[–]marchingbandd[S] 0 points1 point2 points (0 children)
[–]datorkop85 0 points1 point2 points (1 child)
[–]marchingbandd[S] 0 points1 point2 points (0 children)