简体   繁体   English

警告:失败的道具类型:提供给`Dropzone`的类型`string`的prop`child`无效,期望的`function`

[英]Warning: Failed prop type: Invalid prop `children` of type `string` supplied to `Dropzone`, expected `function`

I am using simple Drag and Drop function via Dropzone but Somehow having this error of "Warning: Failed prop type: Invalid prop children of type string supplied to Dropzone , expected function ." 我通过Dropzone使用简单的拖放功能,但不知何故有这个错误“警告:失败道具类型:提供给Dropzone的类型string无效道具children ,预期function 。” I have no idea what it is Na d I have checked the problem doesn't lie anywhere else other than this page 我不知道它是什么Na d我已经检查过问题不在于除了这个页面以外的任何其他地方

import React, { Component } from "react";

import Dropzone from "react-dropzone";

const MaxSize = 1000000000; //
class DragAndDrop extends Component {
  handleOnDrop = (files, rejectedFiles) => {
    console.log(files);
    console.log("rejected files are:", rejectedFiles);
    if (rejectedFiles && rejectedFiles.length > 0) {
      const currentRejectFile = rejectedFiles[0];
      const currentRejectFileType = currentRejectFile.type;
      const currentRejectFileSize = currentRejectFile.size;
      if (currentRejectFileSize > MaxSize) {
        alert(
          "This file is not allowed. " +
            currentRejectFileSize +
            currentRejectFileType +
            " too large"
        );
      }
    }

    if (files && files.length > 0) {
      const currentFile = files[0];
      const currentFileType = currentFile.type;
      const currentFileSize = currentFile.size;
      if (currentFileSize > MaxSize) {
        alert(
          "This file is not allowed. " +
            currentFileSize +
            currentFileType +
            " too large"
        );
      }
    }
  };

  render() {
    return (
      <div>
        <h1>Drop </h1>
        <Dropzone
          onDrop={() => this.handleOnDrop()}
          multiple={false}
          maxSize={MaxSize}
        >
          Drop image here or click to upload
        </Dropzone>
      </div>
    );
  }
}

export default DragAndDrop;

What I want is a simple drap and drop or select and push some image 我想要的是一个简单的下拉或选择并推送一些图像

Try the following: 请尝试以下方法:

<Dropzone
    onDrop={() => this.handleOnDrop()}
    multiple={false}
    maxSize={MaxSize}
>
    { () => Drop image here or click to upload }
</Dropzone>

Here is a useful link: https://www.robinwieruch.de/react-render-props-pattern/ 这是一个有用的链接: https//www.robinwieruch.de/react-render-props-pattern/

Actually It didn't work as they changed the DOCS or maybe something else but I had to change all the code and replace it with this 实际上它没有工作,因为他们改变了DOCS或者其他东西,但我不得不改变所有代码并用它替换它

 import React, { Component } from "react"; import Dropzone from "react-dropzone"; const maxSize = 1048576; //1mb class DragAndDrop extends Component { onDrop = acceptedFiles => { console.log(acceptedFiles); }; render() { return ( <div> <Dropzone onDrop={this.onDrop} accept="image/png, image/gif image/jpg"//whatever the file type needed minSize={0} maxSize={maxSize} multiple > {({ getRootProps, getInputProps, isDragActive, isDragReject, rejectedFiles }) => { const isFileTooLarge = rejectedFiles.length > 0 && rejectedFiles[0].size > maxSize; return ( <div {...getRootProps()}> <input {...getInputProps()} /> {isDragActive ? "Drop it when it's hot!" : "Click me or drag a file to upload!"} {isDragActive && !isDragReject && "Drop it like it's hot!"} {isDragReject && "File type not accepted, sorry!"} {isFileTooLarge && ( <div>File is too large.</div> )} </div> ); }} </Dropzone> </div> ); } } export default DragAndDrop; 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 警告:道具类型失败:提供给“提供者”的对象类型为“对象”的道具儿童无效,需要一个ReactElement - Warning: Failed prop type: Invalid prop `children` of type `object` supplied to `Provider`, expected a single ReactElement 获取错误:警告:道具类型失败:提供给“Form”的道具“children”无效,应为 ReactNode - GETTING ERROR : Warning: Failed prop type: Invalid prop `children` supplied to `Form`, expected a ReactNode 警告:道具类型失败:提供给“ForwardRef(FormControl)”的“string”类型的道具“error”无效,预期为“boolean” - Warning: Failed prop type: Invalid prop `error` of type `string` supplied to `ForwardRef(FormControl)`, expected `boolean` 警告:失败的道具类型:提供给“路由”的“对象”类型的无效道具“组件”,预期的“函数”使用 react-router-dom 错误 - Warning: Failed prop type: Invalid prop `component` of type `object` supplied to `Route`, expected `function` Error using react-router-dom 警告:propType失败:提供给“ LaptopHandling”的类型为“ function”的无效prop`swimmingSnapshot`, - Warning: Failed propType: Invalid prop `swimmingSnapshot` of type `function` supplied to `LaptopHandling`, 道具类型失败:提供给“CSSTransition”的道具“children”无效 - Failed prop type: Invalid prop `children` supplied to `CSSTransition` 警告:道具类型失败:提供给“图片”的道具“源”无效 - Warning: Failed prop type: Invalid prop `source` supplied to `Image` 警告:道具类型失败:提供给“ListItem”的道具“副标题”无效 - Warning: Failed prop type: Invalid prop `subtitle` supplied to `ListItem` 警告:道具类型失败:提供给“路线”的道具属性无效。 在途中 - Warning: Failed prop type: Invalid prop `component` supplied to `Route`. in Route 警告:道具类型失败:提供给 `ForwardRef(Slider)` 的道具 `value` 无效 - Warning: Failed prop type: Invalid prop `value` supplied to `ForwardRef(Slider)`
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM