React.js communicate with state object from outside component

Question!

Using the React DnD lib:

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
            });
        }
    }
});

Wondering how I can add the new "dropped" item into my React component's state object, from the acceptDrop function? What's the usual approach for this kind of thing with React?



Answers

The normal way is using callbacks , you create the function inside the parent component and then put it as props when you call the child.



This video can help you solving your question :)
By: admin