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.

Bug: Should function isControlled use !== ?

See original GitHub issue

React version: 16.20.0

Steps To Reproduce

  1. inital state is undefined , the useAsyncCustomHooks will call an async function eg: navigator.geolocation.getCurrentPosition
  2. the state will changed later

Link to code example:

  function FC() {
    const [state] = useAsyncCustomHooks()
    return <input  type="text" value={state}/>
  }

The current behavior

dev tool throws Warning: A component is changing a controlled input of type hidden to be uncontrolled. Input elements should not switch from controlled to uncontrolled (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

The expected behavior

Not throw that warning, the related source code is: https://github.com/facebook/react/blob/c601f7a64640290af85c9f0e33c78480656b46bc/packages/react-dom/src/client/ReactDOMFiberInput.js#L37-L40

why not !== but != 😊

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
sophiebitscommented, Mar 18, 2020

Many applications rely on a value of undefined to mean an uncontrolled component. If you want to treat undefined to mean a controlled empty box, you can always write something like:

<input type="text" value={state === undefined ? '' : state} />

Hope that helps.

0reactions
xsteadybcgocommented, Mar 18, 2020

Thanks for your reminder, I get it

Read more comments on GitHub >

github_iconTop Results From Across the Web

Insects and their Injury to Plants - CT.gov
Many bugs suck the sap or cell contents from plants as a source of food. ... The use of resistant plant material provides...
Read more >
INSECT FAT BODY: ENERGY, METABOLISM, AND ... - NCBI
Insect adipocytes can store a great amount of lipid reserves as ... The insect fat body plays an essential role in energy storage...
Read more >
The gut microbiota of insects – diversity in structure and function
The microorganisms in insect guts can include protists, fungi, archaea, and bacteria. Protists are best studied in the lower termites and wood roaches, ......
Read more >
Bugs that are fixed in SQL Server 2012 Service Pack 2
Introduction. This article lists the bugs that are fixed in Microsoft SQL Server 2012 Service Pack 2 (SP2). Notes. Additional fixes that are...
Read more >
insect - Hormones, reproduction, senses & behavior
Molting and metamorphosis in insects are controlled by hormones. Reproduction is sexual in almost all insects. They have elaborate sense organs for touch, ......
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