question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Input] Should determine if the component is controlled at the mount time

See original GitHub issue
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

The controlled/uncontrolled behavior is determined at the mount time.

Current Behavior

The controlled/uncontrolled behavior is determined at each render.

Steps to Reproduce (for bugs)

Look at the source code.

Context

@kgregory Raised this issue in #9523. It’s important to notice that the Input component is the only component behaving this way. It’s no the case for: input, Checkbox, Switch, Radio, ExpansionPanel and Tooltip.

Your Environment

Tech Version
Material-UI v1.0.0-beta.24
React v16.2.0

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
Hivemind9000commented, Dec 18, 2017

@oliviertassinari Fair enough, it’s your call - I agree about not making it more complicated (it was more a thought experiment about explicit intention vs implicit behavior).

I dug around to try and understand why React have frowned upon controlled state switching. It appears to only relate to components wrapping the underlying DOM elements of <input> <textarea> and <select>, as they are either directly controlling these elements, or handing control over to the underlying engine. So I’m not convinced it’s a convention - more so a pragmatic wariness (possibly due to performance and/or potential stability issues?) for those specific elements.

One thing to be aware of is that users are already get the warning from react, but it still seems to work (switch control). So I don’t think they’ll notice anything except their code suddenly not working. Perhaps a new warning in Input should be added? Might be nice to have similar warnings if you’re not allowing control switching in other components (or just a note in the docs relating to those specific components/props could be equally effective).

1reaction
oliviertassinaricommented, Dec 28, 2017

Actually, let’s use != null to save some bytes. We have the tests to cover our back.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Input] Should determine if the component is controlled at the ...
The controlled/uncontrolled behavior is determined at the mount time. Current Behavior. The controlled/uncontrolled behavior is determined at ...
Read more >
A component is changing an uncontrolled input to be ...
Hint: you need to choose between controlled and uncontrolled components, so using ref would be solution for it. or Changing value to ...
Read more >
FAQs | React Hook Form - Simple React forms validation
Components mount to the page faster than controlled components because they have less overhead. As a reference, there is a quick comparison test...
Read more >
Uncontrolled Components - React
In a controlled component, form data is handled by a React component. The alternative is uncontrolled components, where form data is handled by...
Read more >
Controlled vs Uncontrolled Components in React - ITNEXT
The data flow is uni-directional from the component state to the input element. Working with controlled components can be a bit cumbersome ....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found