question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: onRemovedFile (or something similar)

See original GitHub issue

I can’t find a way to know when a file has been removed after it has been uploaded. Here is my code below (very similar to your example). For the remove file button, I tried adding an onClick so that I could capture when the user removed the file - but this just overwrites the getRemoveFileProps. So wondering if there is currently a way to know if a file has been removed and if not maybe it could work in a similar way to “onUploadAccepted”, but obviously gets called when the file is removed.

const { CSVReader } = useCSVReader();

<CSVReader
 

  onUploadAccepted={(results: any) => {
    console.log('---------------------------');
    console.log(results);
    console.log('---------------------------');
    setCsvData(results.data)
    setZoneHover(false);
  }}
  onDragOver={(event: DragEvent) => {
    event.preventDefault();
    setZoneHover(true);
  }}
  onDragLeave={(event: DragEvent) => {
    event.preventDefault();
    setZoneHover(false);
  }}
  
>
  {({
    getRootProps,
    acceptedFile,
    ProgressBar,
    getRemoveFileProps,
    Remove,
  }: any) => (
    <>
      <div
        {...getRootProps()}
        style={Object.assign(
          {},
          styles.zone,
          zoneHover && styles.zoneHover
        )}
      >
        {acceptedFile ? (
          <>
            <div style={styles.file}>
              <div style={styles.info}>
                <span style={styles.size}>
                  {formatFileSize(acceptedFile.size)}
                </span>
                <span style={styles.name}>{acceptedFile.name}</span>
              </div>
              <div style={styles.progressBar}>
                <ProgressBar />
              </div>
              <button
              
              
              {...getRemoveFileProps()}
                style={styles.remove}
                onMouseOver={(event: Event) => {
                  event.preventDefault();
                  setRemoveHoverColor(REMOVE_HOVER_COLOR_LIGHT);
                }}
                onMouseOut={(event: Event) => {
                  event.preventDefault();
                  setRemoveHoverColor(DEFAULT_REMOVE_HOVER_COLOR);
                }}
                
              >
                <Remove color={removeHoverColor} />
              </button>
            </div>
          </>
        ) : (
          'Drop CSV file here or click to upload'

        )}
      </div>
    </>
  )}
</CSVReader>

Version 4.0.0

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:5

github_iconTop GitHub Comments

5reactions
Prabashicommented, Apr 5, 2022

In @rishipisipati 's code, replacing

getRemoveFileProps.onClick(event); with

getRemoveFileProps().onClick(event); worked for me. Otherwise it gives an error.

3reactions
rishipisipaticommented, Mar 10, 2022

@Angelfire @DanKellyRedcat @jadenmazzone Not sure if you still need assistance, but this is what worked for me to preserve both the onClick method from removeFileProps and calling in my own code.

              {...getRemoveFileProps()}
                style={styles.remove}
                onMouseOver={(event: Event) => {
                  event.preventDefault();
                  setRemoveHoverColor(REMOVE_HOVER_COLOR_LIGHT);
                }}
                onMouseOut={(event: Event) => {
                  event.preventDefault();
                  setRemoveHoverColor(DEFAULT_REMOVE_HOVER_COLOR);
                }}
               onClick={(event: Event) => {
                 getRemoveFileProps.onClick(event);
                 // Your code here
               }}
Read more comments on GitHub >

github_iconTop Results From Across the Web

[FEATURE REQUEST] Provide `file.absent` with `removedirs` option ...
When that file is no longer needed, file.absent can remove that file, but all directories are kept. ... I'd like to have a...
Read more >
[Feature request] Remove file from version control
Hi, With this post I would like to submit a feature request. It would very usefull if a user could select one or...
Read more >
Where do I go submit a feature request for OneDrive?
To mitigate the risk of mass file deletion on the Cloud by deleting files from our synced folder, I'd like to request a...
Read more >
Feature Request - Individual File 'Revert Local Changes' Review
Should the local copy of this item be deleted? · Should the local copy of this item be accepted into the cluster? ·...
Read more >
107006 - Feature request: ability to replay a previously made ...
Like : - I replay POST requests - I care about POST parameters - I do (don't) care about HTML headers. That way...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found