GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Warn when an input switches between controlled and uncontrolled · Issue #5821 · react/react

Warn when an input switches between controlled and uncontrolled #5821

New issue
Copy link
New issue
Copy link
Closed
#5864
Closed
Warn when an input switches between controlled and uncontrolled#5821
#5864
Copy link
Labels
Difficulty: starter

Description

@jimfb
jimfb
opened on Jan 11, 2016
Issue body actions

A component should either be using uncontrolled inputs or controlled inputs, but not both (they should pick a single paradigm, for the lifetime of the component). As a result, an instance of an input should never switch from controlled to uncontrolled (or vice versa).

We should warn when an input that was previously controlled becomes uncontrolled, or vice versa.

Activity

  1. jimfb
    added
    Difficulty: starter
    on Jan 11, 2016
  2. yangshun commented on Jan 12, 2016

    @yangshun
    yangshun
    on Jan 12, 2016
    Contributor
    More actions

    @jimfb Could you provide some code as to how a controlled input becomes uncontrolled and vice versa?

  3. jimfb commented on Jan 12, 2016

    @jimfb
    jimfb
    on Jan 12, 2016
    ContributorAuthor
    More actions

    @yangshun https://jsfiddle.net/sxqh5csz/

  4. jimfb
    closed this as completedin #5864on Feb 13, 2016
  5. newswim commented on Apr 11, 2016

    @newswim
    newswim
    on Apr 11, 2016
    More actions

    I just got this warning, can anyone point me to an explanation with a bit more detail? ty

  6. brigand commented on Apr 11, 2016

    @brigand
    brigand
    on Apr 11, 2016
    Contributor
    More actions

    @newswim put your code in a stackoverflow question, and link it here.

    Reacted by Dan Minshew
  7. jimfb commented on Apr 11, 2016

    @jimfb
    jimfb
    on Apr 11, 2016
    ContributorAuthor
    More actions

    newswim https://fb.me/react-controlled-components

    Read about controlled components and uncontrolled components. Choose one (preferably controlled components), and don't ever use uncontrolled components. If you are using controlled components, make sure you never pass a null or undefined to React.

    And yes, @brigand is correct, this is better addressed on StackOverflow.

    Reacted by Dan Minshew
  8. rhythnic commented on May 10, 2016

    @rhythnic
    rhythnic
    on May 10, 2016
    More actions

    I don't consider an input's value being null or undefined as a qualifying factor in determining if an input is controlled or uncontrolled. Controlled forms are a paradigm that may share some qualities with uncontrolled forms. It's about listening to changes and updating the state of the value, but React shouldn't stipulate that the value can't be undefined. It's an additional burden to those following good practice in using controlled forms.
    This warning should occur if both defaultValue and value props are used throughout the input's lifecycle.

  9. syranide commented on May 10, 2016

    @syranide
    syranide
    on May 10, 2016
    Contributor
    More actions

    It's an additional burden to those following good practice in using controlled forms.

    I agree, but in the sense that they shouldn't be a single component at all, they should be two separate. Regardless I would say that actually providing the correct string value to an interactive component that expects a string value seems like a rather good practice. Otherwise you will have two distinct value states null and '', but both being intended to mean the exact same thing.

    This warning should occur if both defaultValue and value props are used throughout the input's lifecycle.

    No, because value being null or undefined makes it uncontrolled by definition and you shouldn't switch between controlled and uncontrolled.

    Reacted by Nick Baroni
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: starter

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.