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

Remove value Prop from File Input in React File Upload Example #396

Merged
merged 1 commit into from
Apr 10, 2025

Conversation

JsExpertCoder
Copy link
Contributor

This PR removes the value={data.avatar} attribute from the file input in the React file upload example (resources/js/Pages/file-uploads.jsx). This change addresses two React errors (the application stops, the screen goes black and nothing is rendered when I select a file):

  • Error 1:
    "Warning: value prop on input should not be null. Consider using an empty string to clear the component or undefined for uncontrolled components."
    File inputs are read-only for security reasons, and binding a value can lead to this warning.

  • Error 2:
    "Warning: A component is changing an uncontrolled input to be controlled. This is likely caused by the value changing from undefined to a defined value, which should not happen. Decide between using a controlled or uncontrolled input element for the lifetime of the component."
    Removing the value prop ensures that the file input remains uncontrolled, avoiding the warning.

Solution:

Simply remove value={data.avatar} from the file input. This aligns with best practices for handling file inputs in React and resolves the errors mentioned above.

Note:

I have only tested these changes in an InertiaJS setup using React and Laravel as the backend. I haven't verified the examples for Vue or other frameworks. Please ensure that similar changes for other frontend frameworks are tested accordingly if needed.

@joetannenbaum
Copy link
Contributor

Good catch, thank you 👍

@joetannenbaum joetannenbaum merged commit 1164e9e into inertiajs:master Apr 10, 2025
@JsExpertCoder
Copy link
Contributor Author

I'm the one who thanks! @joetannenbaum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants