Closed DylanPiercey closed 9 years ago
Yes, I'm afraid that's a limitation/design choice from Immutable.js' side. What you'd typically do, is instead design an "API" where you pass down your actions to your elements:
var TodoItem = component(function ({onClick, cursor}) {
return (<div>
<button onClick={onClick.bind(null, cursor)}/>
<strong>{cursor.deref()}</strong>
</div>);
});
// and from parent:
var TodoList = component(function ({listCursor}) {
var remove = function (itemCursor) {
return listCursor.remove(itemCursor);
};
return (<div>
<TodoItem onClick={remove} cursor={listCursor.cursor('0')} />
</div>);
});
Lets say you have a "TodoItem" which is rendered inside of a "TodoList".
The todolist might pass each item a cursor:
Now, without giving the todoitem access to the entire todolist it would be handy if the "TodoItem" could remove itself like so:
This would be pretty handy as currently I'd have to pass down a "requestRemove/onRemove" handler from the parent.
Edit: This is probably a limitation of immutable.js.