1

我正在尝试通过对拖放和查找问题的反应来测试 Dragula。我收到错误消息:

未捕获的类型错误:react_dragula_1.default 不是函数

任何人都遇到过这个问题或解决问题的线索。

import * as React from "react";
import * as ReactDOM from 'react-dom';
import Dragula from 'react-dragula';

export class MultiPicklist extends React.Component {
    render() {
        return (<div className="swish-input-textarea">
                <div className='parent'>
                    <div className='wrapper'>
                        <div id='left-defaults' className='container' ref={this.dragulaDecorator} >
                            <div>Element 0</div>
                            <div>Element 1</div>
                            <div>Element 2</div>
                            <div>Element 3</div>
                        </div>
                        <div id='right-defaults' className='container'>
                            <div>Element a</div>
                            <div>Element b</div>
                            <div>Element c</div>
                            <div>Element d</div>
                            <div>Element e</div>
                        </div>
                    </div>
                </div>
                </div>);
    },
        dragulaDecorator = (componentBackingInstance) => {
            if (componentBackingInstance) {
                let options = { };
                console.log('componentBackingInstance');
                console.log(componentBackingInstance);
                Dragula([componentBackingInstance]);
             }
  };    

}
4

1 回答 1

0

我看到你对 ES6 类语法有点混乱。尝试将 ref 回调拉到类定义之外:

import * as React from "react";
import * as ReactDOM from 'react-dom';
import Dragula from 'react-dragula';

export class MultiPicklist extends React.Component {
    render() {
        return (<div className="swish-input-textarea">
                <div className='parent'>
                    <div className='wrapper'>
                        <div id='left-defaults' className='container' ref={dragulaDecorator} >
                            <div>Element 0</div>
                            <div>Element 1</div>
                            <div>Element 2</div>
                            <div>Element 3</div>
                    </div>
                        <div id='right-defaults' className='container'>
                            <div>Element a</div>
                            <div>Element b</div>
                            <div>Element c</div>
                            <div>Element d</div>
                            <div>Element e</div>
                        </div>
                    </div>
                </div>
                </div>);
    }

}  
const dragulaDecorator = (componentBackingInstance) => {
        if (componentBackingInstance) {
            let options = { };
            console.log('componentBackingInstance');
            console.log(componentBackingInstance);
            Dragula([componentBackingInstance]);
         }
};

您还可以在类方法中使用 ES6 箭头函数,但为此您需要在 Babel 中启用实验功能才能编译它。检查此 SO 问题以获取更多详细信息:https ://stackoverflow.com/a/31362350/4642844

于 2016-08-28T23:44:28.503 回答