首页 > 解决方案 > react-simple-file-upload:尝试导入错误

问题描述

我正在尝试使用 Heroku 的新插件:react-simple-file-upload。文献上说要安装“npm install react-simple-file-upload”,然后通过以下方法导入:

import { SimpleFileUpload } from 'react-simple-file-upload'

  <SimpleFileUpload
    apiKey="..."
    onSuccess={handleFile}
  />

  function handleFile(url){
    console.log('The URL of the file is ' + url)
  }

我已经非常准确地遵循了这一点,但不断收到错误消息:

Attempted import error: 'SimpleFileUpload' is not exported from 'react-simple-file-upload'.
console.<computed> @ index.js:1375

我的代码如下所示:

import React from "react";
import { SimpleFileUpload } from 'react-simple-file-upload';

const About = () => (
  <div>
    <SimpleFileUpload
    apiKey="d0a36142ceb56a2c9295eac2feecc8ce"
    onSuccess={handleFile}
  />
    <h1 className="title is-1">Work in Progress</h1>
    <p>
      This site is a work in progress as of December 25th, 2020. 
    </p>
  </div>
);

export default About;

标签: javascriptreactjsherokufile-upload

解决方案


这是蹩脚的文档。这是默认导出。这应该可以解决问题。

import SimpleFileUpload from 'react-simple-file-upload'

请参阅此处的代码。

https://github.com/pixelplicity/react-simple-file-upload/blob/master/src/index.js


推荐阅读