props will be involved whenever you use a component more than once on the same page to represent separate business entities.
As I said before
I need to mention that the identity of Component is not always the same as the identity of Instance of Component. That's why in some framework you need to specify the key.
although there are no real key here but different update props are passed to identify different entities. In certain degree it's the mismatch between UI and application proved again.
and the solution is fairly simple... encapsulate High Order Component
although it's not necessary to involve any architecture decision, I'm placing the kairo's solution here
const[External,ExternalImpl]=createConcreteConcern('External',function*(){const[leftValue,setLeft]=yield*State(0);const[rightValue,setRight]=yield*State(0);return{leftValue,rightValue,setLeft,setRight}});// a shortcut of `createConcern` with a default implementationconstValue=UI(function*({value,setValue}:{value:Cell<number>,setValue:Setter<number>}){constonChange=e=>setValue(e.target.value);returnComponent((_,$)=>(<span><inputvalue={$(value)}onChange={onChange}/></span>));});constApp=UI(function*(){const{leftValue,rightValue,setLeft,setRight}=yield*External;constLeft=yield*Include(Value.withProps({value:leftValue,setValue:setLeft}));constRight=yield*Include(Value.withProps({value:rightValue,setValue:setRight}));returnComponent((_,$)=>(<divclassName="App"><h1>Totals</h1><Left/><Right/>
total is {$(leftValue)+$(rightValue)}</div>));});
notably I made Value fully controlled because it's unnecessary to have a local state as there is already a source of truth.
@peerreynders regarding Actor-Model you mentioned in this thread, you might be interested in this lib: reatom.dev/ (but it also relevant to the overall discussion)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
As I said before
although there are no real
key
here but differentupdate
props are passed to identify different entities. In certain degree it's the mismatch between UI and application proved again.and the solution is fairly simple... encapsulate High Order Component
although it's not necessary to involve any architecture decision, I'm placing the
kairo
's solution herenotably I made
Value
fully controlled because it's unnecessary to have a local state as there is already a source of truth.@peerreynders regarding Actor-Model you mentioned in this thread, you might be interested in this lib: reatom.dev/ (but it also relevant to the overall discussion)