React Binding to ObservableState
See original GitHub issueActually, to bind my ObservableState
to a React component, I’m wrapping it into a div
:
div(store) {
react {
awesomeExternalReactComponent {
(...)
}
}
}
I tried to workaround this extra div
but, unfortunately, using the builtin extension bind(store, true, factory)
doesn’t quite work as expected since the React
widget is not a Container
and we’re ending up with duplicated react components on every state update since removeChildren
is ignored:
// Homemade version, trying to skip the extra <div>
fun <S> Container.react(
state: ObservableState<S>,
classes: Set<String>? = null,
className: String? = null,
builder: RBuilder.(S) -> Unit): Widget {
return react(classes = classes, className = className) {
builder(state.value)
}.bind(state, true) { // remove children *NOT* working
react(classes = classes, className = className) {
builder(it)
}
}
}
Is that the expected behavior or can it be filled as a bug?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to bind React state to RxJS observable stream?
Update. To abstract out some of the below complexity, use recompose's mapPropsStream or componentFromStream. E.g.
Read more >bind(observable) - React-RxJS
Binds an Observable factory function to React, and returns a hook and shared stream representing the created Observables. Copy. function bind<A extends unknown ......
Read more >How to bind React state to RxJS observable stream?-Reactjs
[Solved]-How to bind React state to RxJS observable stream?-Reactjs. Search. score:2. Accepted answer. One option could be to use Rx.Observable.
Read more >RxJS with React Hooks for state management - LogRocket Blog
An Observer consumes the data supplied by an Observable. In our demo app, we'll be using our setState Hook to consume data from...
Read more >React integration - MobX
As a rule of thumb, use MobX observables when the state captures domain data that is shared among components (including children). Such as...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think there is no need to use
bind
forReact
component, because it already supports state management. You just need to connect your component to your store. You can do this with a single line:Or you can create a DSL builder function like this:
And you can use it:
I’ll add this DSL function to the next KVision release.
Fixed in 3.16.1