Skip to content

Commit

Permalink
Simplify onFileChange callback
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed May 14, 2024
1 parent 37ae6e0 commit 057a928
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
6 changes: 4 additions & 2 deletions sample/create-react-app-5/src/Sample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ export default function Sample() {
function onFileChange(event: React.ChangeEvent<HTMLInputElement>): void {
const { files } = event.target;

if (files && files[0]) {
setFile(files[0] || null);
const nextFile = files?.[0];

if (nextFile) {
setFile(nextFile);
}
}

Expand Down
6 changes: 4 additions & 2 deletions sample/next-app/app/Sample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ export default function Sample() {
function onFileChange(event: React.ChangeEvent<HTMLInputElement>): void {
const { files } = event.target;

if (files && files[0]) {
setFile(files[0] || null);
const nextFile = files?.[0];

if (nextFile) {
setFile(nextFile);
}
}

Expand Down
6 changes: 4 additions & 2 deletions sample/next-pages/pages/Sample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ export default function Sample() {
function onFileChange(event: React.ChangeEvent<HTMLInputElement>): void {
const { files } = event.target;

if (files && files[0]) {
setFile(files[0] || null);
const nextFile = files?.[0];

if (nextFile) {
setFile(nextFile);
}
}

Expand Down
6 changes: 4 additions & 2 deletions sample/parcel2/Sample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ export default function Sample() {
function onFileChange(event: React.ChangeEvent<HTMLInputElement>): void {
const { files } = event.target;

if (files && files[0]) {
setFile(files[0] || null);
const nextFile = files?.[0];

if (nextFile) {
setFile(nextFile);
}
}

Expand Down
6 changes: 4 additions & 2 deletions sample/vite/Sample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ export default function Sample() {
function onFileChange(event: React.ChangeEvent<HTMLInputElement>): void {
const { files } = event.target;

if (files && files[0]) {
setFile(files[0] || null);
const nextFile = files?.[0];

if (nextFile) {
setFile(nextFile);
}
}

Expand Down
6 changes: 4 additions & 2 deletions sample/webpack5/Sample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ export default function Sample() {
function onFileChange(event: React.ChangeEvent<HTMLInputElement>): void {
const { files } = event.target;

if (files && files[0]) {
setFile(files[0] || null);
const nextFile = files?.[0];

if (nextFile) {
setFile(nextFile);
}
}

Expand Down

0 comments on commit 057a928

Please sign in to comment.