How to use jQuery UI in React JS

StackOverflow answer: http://stackoverflow.com/a/40350880/1333836

by Kaloyan Kosev

HTML

<script src="https://npmcdn.com/[email protected]/dist/react-dom.js"></script>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.0/themes/smoothness/jquery-ui.css">
<div id="app"></div>

CSS

/**
Just to beautify the things a bit
*/
ul { margin: 10px; padding: 0; }
li { list-style-type: none; padding: 10px 5px; cursor: pointer;  }
.ui-sortable-disabled li { cursor: not-allowed; }

Babel + JSX

/**
 * An example how to use Jquery UI Sortable with React JS!
 *
 * The plan: Create a component to manage the jQuery plugin.
 * Full details and explanation:
 *  - See my StackOverflow answer - http://stackoverflow.com/a/40350880/1333836
 *  - Gist: https://gist.github.com/superKalo/a7b1fa9d68fbae6cdbf66be7d0588937
 */
class Sortable extends React.Component {
    componentDidMount() {
        // Every React component has a function that exposes the
        // underlying DOM node that it is wrapping. We can use that
        // DOM node, pass it to jQuery and initialize the plugin.

        // You'll find that many jQuery plugins follow this same pattern
        // and you'll be able to pass the component DOM node to jQuery
        // and call the plugin function.

        // Get the DOM node and store the jQuery element reference
        this.$node = $(this.refs.sortable);

        // Initialize the jQuery UI functionality you need
        // in this case, the Sortable: https://jqueryui.com/sortable/
        this.$node.sortable({
            // Get the incoming `opacity` prop and use it in the plugin configuration
            opacity: this.props.opacity,
            // Get the incoming onChange func and we invoke it on the Sortable `change` event
            change: (event, ui) => this.props.onChange(event, ui)
        });
    }
    
    // Force a single-render of the component,
    // by returning false from shouldComponentUpdate ReactJS lifecycle hook.
    // Right after ReactJS adds the element in the actual DOM,
    // we need to pass the future control to jQuery.
    // This way, ReactJS will never re-render our component,
    // and jQuery will be responsible for all updates.
    shouldComponentUpdate() {
        return false;
    }

    componentWillReceiveProps(nextProps) {
        // Each time when component receives new props,
        // we should trigger refresh or perform anything else we need.
        // For this example, we'll update only the...