Skip to content

Commit d6fd3cc

Browse files
committed
feature: remove specific file
1 parent 2017715 commit d6fd3cc

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

build/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/src/App.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,17 @@ function App() {
4040
setLastError(null);
4141
};
4242

43+
const deleteFile = (file) => {
44+
wrapperRef.current.removeFile(file);
45+
};
46+
4347
return (
4448
<div className="App">
4549
<FileTrap
4650
ref={wrapperRef}
4751
handleDrag={handleDrag}
4852
handleDrop={handleDrop}
53+
fileCount={10}
4954
onValidationError={onValidationError}
5055
handleChange={handleChange}
5156
browseOnClick={false}
@@ -69,7 +74,7 @@ function App() {
6974
<h2 style={{ margin: 5 }}>Valid Files</h2>
7075
<hr></hr>
7176
<ul>
72-
{validFiles.map((file, index) => <li key={index}>{file.name}</li>)}
77+
{validFiles.map((file, index) => <li key={index}>{file.name} <button style={{ margin: 1 }} onClick={() => deleteFile(file)}>Delete</button></li>)}
7378
</ul>
7479
<h2 style={{ margin: 5 }}>Invalid Files</h2>
7580
<hr></hr>

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ const FileTrap = React.forwardRef((props, ref) => {
1919

2020
useImperativeHandle(ref, () => ({
2121
browseFiles: () => { browseFiles(null, true); },
22-
resetWrapper: () => { setFileList([]); }
22+
resetWrapper: () => { setFileList([]); },
23+
removeFile: (file) => { setFileList(fileList.filter(f => f !== file)); }
2324
}));
2425

2526
// triggers when fileList changes

0 commit comments

Comments
 (0)