簡體   English   中英

React.js與外部組件的狀態對象進行通信

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM