Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: react-dom.development.js:1571 Uncaught InvalidStateError when handling file input in React 16.13.1 #32753

Open
vaish8529 opened this issue Mar 26, 2025 · 0 comments
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@vaish8529
Copy link

React version:
"react": "^16.13.1",
"react-bootstrap": "^1.0.1",
"react-dom": "^16.13.1",

Steps To Reproduce

1.Upload file from browser
2.Issue persist

`import React, { useState } from "react";

const FileUpload = () => {
const [basicDetails, setBasicDetails] = useState({});
const [docPreview, setDocPreview] = useState({
pan_preview: "",
aadhaar_preview: "",
bank_preview: "",
education_preview: "",
});

const handleFileChange = (event) => {
    const { files, name } = event.target;

    if (files && files.length > 0) {
        const selectedFile = files[0];
        const newUrl = URL.createObjectURL(selectedFile);

        setBasicDetails((prev) => ({
            ...prev,
            [name]: newUrl,
        }));

        setDocPreview((prev) => ({
            ...prev,
            ...(name === "document_pan_card" && { pan_preview: newUrl }),
            ...(name === "document_aadhaar_card" && { aadhaar_preview: newUrl }),
            ...(name === "document_bank_passbook" && { bank_preview: newUrl }),
            ...(name === "document_education_proof" && { education_preview: newUrl }),
        }));
    }
};

return (
    <div className="container">
        <div className="col-3">
            <label htmlFor="document_pan_card">Pan Card</label>
            <div className="custom-file mb-4">
                <input
                    type="file"
                    accept="image/*"
                    onChange={handleFileChange}
                    className="custom-file-input"
                    name="document_pan_card"
                    id="document_pan_card"
                    aria-describedby="document_pan_card"
                />
                <label className="custom-file-label" htmlFor="document_pan_card">
                    Upload Document
                </label>
            </div>

            {/* Document Preview */}
            <div className="form-group row justify-content-around">
                {docPreview.pan_preview && (
                    <div className="align-items-center justify-content-center mb-4">
                        <img
                            src={docPreview.pan_preview}
                            alt="PAN Preview"
                            width="200"
                            height="200"
                            style={{ border: "1px solid #ccc", padding: "5px" }}
                        />
                    </div>
                )}
            </div>
        </div>
    </div>
);

};

export default FileUpload;`

@vaish8529 vaish8529 added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Mar 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

1 participant