Bunlong / react-papaparse

react-papaparse is the fastest in-browser CSV (or delimited text) parser for React. It is full of useful features such as CSVReader, CSVDownloader, readString, jsonToCSV, readRemoteFile, ... etc.
https://react-papaparse.js.org
MIT License
364 stars 61 forks source link

Cannot stream or chunk with CSVReader #59

Closed naathanbrown closed 3 years ago

naathanbrown commented 4 years ago

Hi,

I am trying to chunk a CSV file on upload with CSVReader using the callback as said in documentation. My current attempt looks like

                onDrop={handleOnDrop}
                onError={handleOnError}
                config={{header:true, worker: true, skipEmptyLines: true,
                    step: (results:any, parser:any) => {
                        console.log("hello")
                        console.log("Row data:", results.data)
                        console.log("Row errors:", results.errors)
                    },
                    complete: () => console.log("Done!")
                }}
                addRemoveButton
                onRemoveFile={handleOnRemoveFile}
            >
                <span>Drop CSV file here or click to upload.</span>
            </CSVReader>

Currently the data is never displayed to the console in any way and I cannot understand why?

Any help would be greatly appreciated, thank you!

Bunlong commented 4 years ago

@naathanbrown Please check the Demo and Source code. Thanks!

naathanbrown commented 4 years ago

@Bunlong Hi thanks for that, I've read all that and I'm still having issues, I realised my whole code snippet did not paste, sorry for this.

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

const Csv = () => {
    const handleOnDrop = (data: any) => {

        console.log("---------------------------");

        console.log(data);
    };
    const handleOnError = (err: any) => {
        console.log(err);
    };

    const handleOnRemoveFile = (data: any) => {
        console.log("---------------------------");
        console.log(data);
        console.log("---------------------------");
    };

    return (
        <>
            <h5>Click and Drag Upload</h5>
            <CSVReader
                onDrop={handleOnDrop}
                onError={handleOnError}
                config={{header:true, worker: true, skipEmptyLines: true,
                    step: (results:any, parser:any) => {
                        console.log("hello")
                        console.log("Row data:", results.data)
                        console.log("Row errors:", results.errors)
                    },
                    complete: () => console.log("Done!")
                }}
                addRemoveButton
                onRemoveFile={handleOnRemoveFile}
            >
                <span>Drop CSV file here or click to upload.</span>
            </CSVReader>
        </>
    );
};

export default Csv;

I may be missing something silly and I haven't noticed but any advice will help a lot, thank you!

To clarify none of the console.logs run within the step callback function, so I am unsure how I can access the data being stepped?

Tinkvision commented 3 years ago

Same issue for me ;)

MaxAst commented 3 years ago

same issue here. It looks like the step callback is getting deleted from the config object https://github.com/Bunlong/react-papaparse/blob/master/src/CSVReader.tsx#L280-L288, so that any callback passed as part of the config prop never runs. Or am I missing something?

MaxAst commented 3 years ago

this could fix it: https://github.com/Bunlong/react-papaparse/pull/65

kurroo10 commented 3 years ago

can someone help me ? i try to proccess the data after file is completely loaded, but its never working for me.

trying this :

config={{
     complete: () => console.log("Done!")
}}

but sadly, its never triggered, even step is not trigger also. can someone help me ? because if i used onFileLoaded and set states, it will crash / freeze my browser instead of continue load the files.