Comments (4)
Hi,
It's nice to see you try my library intensively.
Wow, so many points here, let me respond each.
What do you think about these patterns?
Gallery/Gallery.tsx
This pattern is pretty much the same as what I do in react-tracked.
It's going to be like this
import { createContainer } from 'react-tracked'
const useGalleryState = () => {
console.log('state')
const [searchTerm, setSearchTerm] = useState('')
const { status, data } = useQuery([searchTerm], fetch)
return [{
isLoading: status === 'loading',
data,
searchTerm,
}, setSearchTerm]
}
export const {
Provider,
useSelector: useGalleryContext,
useUpdate: useSetSearchTerm,
} = createContainer(useGalleryState)
There is also performance test.
Please note that when you test performance you'd want to use production build to get real numbers.
Thinking towards useReducer and will experiment with your useAsyncReducer.
Check this out, if you haven't: https://react-tracked.js.org/docs/tutorial-04
Btw it is slower than yours.
Looking at their code, I'm not quite sure why so different.
BTW, I already developed a next major version: #12
what is the actual reason to manage immutable store, other than time travel ?
(not sure what you mean by time travel)
About the immutability (wouldn't call immutable store, because store is mutable. state objects are immutable), it's in a sense a preference or a style. For example, we have Redux and MobX. Both are good and not interchangeable.
However, React itself leans to immutability. It supports both patterns (immutable and mutable) by default, but React.PureComponent
and React.memo
are for the immutable pattern.
With upcoming Concurrent Mode, it allows to branch state, so the mutable pattern will have some difficulties. In short, the immutable pattern fits better with React philosophy.
The question arose when it was easier for me to put an array with other methods into useRef, mutate it in the methods and just call 'forceUpdate'. It worked. So what is the reason to manage immutability ?
It works in legacy mode, but it will not in concurrent mode. That's the reason. Basically, you want to avoid using useRef for "states". It behaves unexpectedly in concurrent mode.
I used to use forceUpdate hack a lot in my various libs, but not any more.
from use-context-selector.
Yes, right, in production the two variants do not differ.
The difference though when passing props or memoized vs context is still substantial. But even if to neglect it, there is additional benefit of the convenience of not passing props and not declaring their types, etc.
Yes, I see there is 2alpha of the useMutableSource. For the react-tracked you also developing 2nd version.
Yes, because the react way is immutability, this is the reason I once started looking into redux at all. Mobx was so convenient. But for certain things Mobx problematic. I did this form lib https://github.com/lishine/mobx-hooks-form. And because of accessing dynamic path form.a.b.c I had to do some workaround. Mobx way is the way of Rxjs, observables etc, it is different world.
Will start looking into react-tracked. But it is more heavy. Good for app.
I would convert this form lib to use use-context-selector. Then I would want the lightest store so that lib size will be small. Probably useReducer+use-context-selector will be enough. There is debouncing there though. Will see.
Pattern of asyncActionHandler of use-reducer-async reminds me of thunk of easy-peasy. They have createContextStore btw.
from use-context-selector.
there is additional benefit of the convenience of not passing props and not declaring their types
I'm not sure if I understand this.
Mobx was so convenient.
I don't have much experience with MobX, but it you like it, you might like react+tracked + immer. I hope this combination gives similar DX. I'm interested in your feedback on it. No rush.
from use-context-selector.
Closing as stale. Please open a new one if needed.
from use-context-selector.
Related Issues (20)
- broken in react 18 HOT 7
- trigger other rerender use official demo
- Is it possible to create a strict context with this library? HOT 8
- [question] unexpected component render when first set different state HOT 4
- [question] Why is the scheduler dependency required? HOT 5
- Difference between this package and `@fluentui/react-context-selector` HOT 1
- Can you review my hook? (useKeyedContextSelector) HOT 2
- Don't work with react 18.2 HOT 10
- React Native: Crash occurs when using `createContext` and `MyContext.Provider` after updating to react-native v0.72 or later HOT 7
- Update occurs asynchronously after selection function runs HOT 1
- Version 1.4.2 specifies main module field that cannot be resolved HOT 16
- useMemo vs useContextSelector HOT 1
- Issue is back, missing some kind of export for react native. HOT 5
- `createContext` breaks tests with `@testing-library/react-native` and `vitest` HOT 3
- In useContextSelector(.., selector: (v) => ...) the argument v is not the valid context value type HOT 2
- I have a question about state rendering time HOT 2
- [Question] Getting several context values at once? HOT 7
- "useContextSelector requires special context" warning is never printed HOT 3
- `yarn compile` fails HOT 1
- The component doesn't redraw, but the component function is still executed HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from use-context-selector.