1

I have a react app running with webpack and I want to make an element draggable using jquery UI. I've added the library with

How can I import jquery ui into the component

Error: (...).draggable is not a function $(this.productElm).draggable({

//Install:
yarn add jquery-ui  

// Component file:

import $ from "jquery";
import draggable from 'jquery-ui';

export class Item extends React.Component {
  componentDidMount(){
     this.setPlacement();
     document.addEventListener('mousedown', this.handleOutsideClick, false)
      this.initInterations()
  }

initInterations(){
    setTimeout(() => {
      $(this.productElm).draggable({
        addClasses: false,
        stop: (e, ui) => {
          if(this.props.onChange){
            this.props.onChange({
              name: 'move',
              x: ui.position.left,
              y: ui.position.top
            }, this.props.item)
          }
        }
      })
    })
  }
}

1 Answer 1

1

Seems like you can import the various jquery ui 'widgets' like this

import 'jquery-ui/ui/widgets/draggable';
import 'jquery-ui/ui/widgets/resizable';

To work out the path for the import, lookin the node modules folder for what you are importing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.