Comments (8)
React's new context API might adopt the render props pattern.
This discussion in the RFC might be useful for this proposal. It's a very long threads though😅
It is difficult to type component for HOC.
I agree with you.
Unfortunately, In addition to that, flowtype has some issues related typing with HOC.
from almin.
Thanks for suggestion :)
from almin.
Instersting approach
https://github.com/thejameskyle/unstated
from almin.
Image(I do not try to implement this image yet...)
import { StoreGroup, Context } from "almin";
const storeGroup = new StoreGroup({
app: new AppStore(),
counter: new CounterStore();
});
const context = new Context({ store: storeGroup });
function Counter() {
return (
<Subscribe to={[AppStore, CounterStore]}>
{(app, counter) => (
<div>
<span>Count: {counter.state.count}</span>
<button onClick={() => context.useCase(new DecrementUseCase()).execute()}>-</button>
<button onClick={() => context.useCase(new IncrementUseCase()).execute()}>+</button>
</div>
)}
</Subscribe>
);
}
function App() {
return (
<Subscribe to={[AppStore]}>
{app => (
<div>
<Counter />
<label>Amount: </label>
<input
type="number"
value={app.state.amount}
onChange={event => {
context.useCase(new IncrementUseCase()).execute();
}}
/>
</div>
)}
</Subscribe>
);
}
render(
<Provider context={context}>
<App />
</Provider>,
window.complex
);
from almin.
Article: React’s ⚛️ new Context API – DailyJS – Medium
from almin.
from almin.
Related Context API based design::
- React 16 experiment: rewrite React-Redux to use new context API by markerikson · Pull Request #898 · reactjs/react-redux
- jamiebuilds/unstated: State so simple, it goes without saying
- Refactor with new React Context API · Issue #448 · mobxjs/mobx-react
from almin.
Implemented @almin/react-context
from almin.
Related Issues (20)
- AlminPerfMarker should not throw error HOT 7
- Almin: Store#receivePayload design HOT 5
- almin-react-container: Convert tests to TypeScript
- LifeCycleEventHub#onDispatch receive StoreChangedPayload
- almin: remove `dispatcher` from `DispatcherPayloadMeta` HOT 1
- Almin: `transaction` property in Meta should be readonly HOT 2
- almin: use `assert` function instead of Node "assert" module
- Docs: warning as document
- Almin 0.17
- @almin/store-test-helper
- Drop to use `events`
- Support module field
- Deprecate `executor()`
- Almin 0.18 CHANGELOG
- Lerna 3 bug and workaround HOT 1
- Retire zuul HOT 2
- CI: GitHub Actions
- Action Required: Fix Renovate Configuration HOT 1
- Support React Hooks
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 almin.