You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to find out what the best way is to have multiple instances of the same react component in the same app with flummox.
Library is a component that loads data from the specified url and displays it as a filterable list. let's say, I wanted to have two of those lists, but with different data sources. — how would I do that?
what seems to work is to simply create multiple Flux instances, one for each list:
however, being new to (flux /) flummox, I'm not sure if it is supposed to be used like this.
also, what if a third component needed to react to actions from the two list components?
so I tried s.th. like this: only a single Flux instance, but instead creating multiple actions / store instances with different "names".
classAppFluxextendsFlux{constructor(){super();this.createActions('library',LibraryActions);this.createStore('library',LibraryStore,this,'library');// tell store which name to usethis.createActions('model-library',LibraryActions);this.createStore('model-library',LibraryStore,this,'model-library');}}constflux=newAppFlux();React.render(<FluxComponentflux={flux}connectToStores={['library']}><Libraryurl='data/lib.json'libName='library'/></FluxComponent>,$('#test-library')[0]);React.render(<FluxComponentflux={flux}connectToStores={['model-library']}><Libraryurl='data/models.json'libName='model-library'/> // tell component which name to use
</FluxComponent>,$('#model-library')[0]);
Here is another one: you could keep a single store and key the data in your store's state based on some id. The source perhaps? Then provide a custom state getter for connectToStores and retrieve the data through a custom method on your store, for example store.getDataForSource('data/models.json').
Yes that's right, but you could probably get away with a good shouldComponentUpdate check. It depends all on the performance of the overall system. If this runs 60 times per second might be a problem. If not, I assume that it's probably negligible.
hi,
I am trying to find out what the best way is to have multiple instances of the same react component in the same app with flummox.
Library
is a component that loads data from the specified url and displays it as a filterable list. let's say, I wanted to have two of those lists, but with different data sources. — how would I do that?what seems to work is to simply create multiple
Flux
instances, one for each list:however, being new to (flux /) flummox, I'm not sure if it is supposed to be used like this.
also, what if a third component needed to react to actions from the two list components?
so I tried s.th. like this: only a single
Flux
instance, but instead creating multiple actions / store instances with different "names".LibraryStore.js:
Library.js:
this feels a bit cumbersome, but works...
any suggestions, how to properly do this?
thanks a lot in advance.
The text was updated successfully, but these errors were encountered: