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

Input: when both value and onChange are set, will produce the uncontrolled/controlled input error #1923

Closed
wyemun opened this issue Aug 3, 2017 · 3 comments

Comments

@wyemun
Copy link

wyemun commented Aug 3, 2017

Steps

Setting up an <Input/> as such

<Input
              fluid
              placeholder="Search by keywords. Press `Enter` to search."
              icon="search"
              disabled={isDisabled}
              value={query}
              onChange={this.onSearchFieldChange}
              onKeyDown={this.onSearchKeyDown}
              label={
                <Dropdown basic
                  value={queryColumn}
                  options={searchColumns}
                  onChange={this.onQueryColumnChange}
                />
              }
              labelPosition="right"
            />

Expected Result

Expected no react error thrown.

Actual Result

Console is logging the following error:

proxyConsole.js:56 Warning: Input is changing an uncontrolled input of type text to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component. More info: https://fb.me/react-controlled-components

If anything at all, this should be the correct way of implementing both onChange and value according to https://fb.me/react-controlled-components

Version

0.71.3

@layershifter
Copy link
Member

layershifter commented Aug 3, 2017

Please make a minimal codepen. I understand that the codepen uses production versions, but I want simply to copy-paste the code that causes warning.

Input has a state managed by AutoControlledComponent and I don't see cases when it pass wrong value.

@layershifter
Copy link
Member

Closing for housekeeping.

@levithomason
Copy link
Member

levithomason commented Aug 20, 2017

With a controlled component, the value must always be a string otherwise React will complain. Your query is likely not defined on the first render.

Note the default string in the docs you've linked:

this.state = {value: ''};

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

No branches or pull requests

3 participants