[英]React.js communicate with state object from outside component
使用React DnD庫:
const itemDropTarget = {
acceptDrop(component, item) {
window.alert('You dropped ' + item.name + '!');
}
};
const Container = React.createClass({
mixins: [DragDropMixin],
getInitialState() {
return {
items: []
};
},
statics: {
configureDragDrop(register) {
register(ItemTypes.ITEM, {
dropTarget: itemDropTarget
});
}
}
});
想知道如何從acceptDrop
函數將新的“放置”項添加到React組件的state
對象中? 用React處理這種事情的通常方法是什么?
通常的方法是使用回調,您可以在父組件內部創建函數,然后在調用子組件時將其作為道具。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.