尝试使用 react-papaparse 逐行流式传输本地文件,但它不起作用 - 我编码正确还是不可能?

问题描述

我可以使用 react-papaparse 来解析触发 onFileLoad={this.handleOnFileLoad} 的本地文件,但是我想流式传输它,所以我尝试了下面的代码,试图传递 onStep 或 step in props 但它的不触发。文档暗示这是可能的,但我是否以错误的方式解决这个问题?我想一次处理每一行,以防它是一个非常大的文件。谢谢。

import React from 'react';
import { CSVReader } from 'react-papaparse';

const buttonRef = React.createRef();

export default class CSVReader1 extends React.Component {
  handleOpenDialog = (e) => {
    // Note that the ref is set async,so it might be null at some point
    if (buttonRef.current) {
      buttonRef.current.open(e);
    }
  };
  handleOnStep = (row) => {
    console.log('handleOnComplete---------------------------');
    console.log(row);
    console.log('---------------------------');
  };
  handleOnError = (err,file,inputElem,reason) => {
    console.log('handleOnError---------------------------');
    console.log(err);
    console.log('---------------------------');
  };
  handleOnRemoveFile = (data) => {
    console.log('handleOnRemoveFile---------------------------');
    console.log(data);
    console.log('---------------------------');
  };
  handleRemoveFile = (e) => {
    // Note that the ref is set async,so it might be null at some point
    if (buttonRef.current) {
      buttonRef.current.removeFile(e);
    }
  };
  render() {
    return (
      <CSVReader
        ref={buttonRef}
        onError={this.handleOnError}
        onStep={this.handleOnStep}
        noClick
        noDrag
        onRemoveFile={this.handleOnRemoveFile}
      >
        {({ file }) => (
          <div className="form">
            <div>
              <button className="button" type="button" onClick={this.handleOpenDialog} >browse file</button>
            </div>
            <div className="text-input">
              {file && file.name}
            </div>
            <div>
              <button className="button button--secondary" onClick={this.handleRemoveFile}>Remove</button>
            </div>
          </div>

        )}
      </CSVReader>

    );
  };
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)