使用fineuploader和react-rails

时间:2017-10-03 08:55:01

标签: javascript ruby-on-rails reactjs fine-uploader

我正在尝试使用fineuploader with react并安装了所有相关的依赖项。 以下是我使用的代码: -

import React, { Component } from 'react'

import FineUploaderTraditional from 'fine-uploader-wrappers'
import Gallery from 'react-fine-uploader'

import 'react-fine-uploader/gallery/gallery.css'

const uploader = new FineUploaderTraditional({
    options: {
        chunking: {
            enabled: true
        },
        deleteFile: {
            enabled: true,
            endpoint: '/uploads'
        },
        request: {
            endpoint: '/uploads'
        },
        retry: {
            enableAuto: true
        }
    }
})

class UploadComponent extends Component {
    render() {
        return (
            <Gallery uploader={uploader} />
        )
    }
}

export default UploadComponent

但我收到以下错误: -

Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in. Check the render method of `Gallery`.
at invariant (invariant.js?7313:44)
at instantiateReactComponent (instantiateReactComponent.js?e676:74)
at instantiateChild (ReactChildReconciler.js?c86a:44)
at eval (ReactChildReconciler.js?c86a:71)
at traverseAllChildrenImpl (traverseAllChildren.js?5edf:77)
at traverseAllChildrenImpl (traverseAllChildren.js?5edf:93)
at traverseAllChildrenImpl (traverseAllChildren.js?5edf:93)
at traverseAllChildren (traverseAllChildren.js?5edf:172)
at Object.instantiateChildren (ReactChildReconciler.js?c86a:70)
at ReactDOMComponent._reconcilerInstantiateChildren (ReactMultiChild.js?e1f8:185)
  

警告:React.createElement:type无效 - 需要一个字符串   (对于内置组件)或类/函数(对于复合   组件)但得到:未定义。你可能忘了导出你的   来自其定义的文件中的组件。检查。的render方法   `Gallery`。
  在Gallery中(由UploadComponent创建)
  在UploadComponent

我一直在关注反应精细上传文档,我尝试了一些不同的东西,但似乎没什么用。

2 个答案:

答案 0 :(得分:5)

问题是一些未满足的依赖,在我的例子中是:

react-transition-group@1.x

我有

react-transition-group@2.x

删除2.x并安装1.2.1解决了问题。

密切关注您尝试配置的任何软件包的安装依赖性。

感谢react-fine-upload所有者rnicholus 的帮助。

答案 1 :(得分:0)

我认为您必须从模块中导入Gallery组件。

import Gallery from 'react-fine-uploader'


更新:
同时尝试在div

中包装Gallery
class UploadComponent extends Component {
    render() {
        return (
          <div>
            <Gallery uploader={uploader} />
          </div>
        )
    }
}