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 - Updating value from other source #186

Open
mmj-ssb opened this issue Mar 12, 2020 · 2 comments
Open

Input - Updating value from other source #186

mmj-ssb opened this issue Mar 12, 2020 · 2 comments

Comments

@mmj-ssb
Copy link

mmj-ssb commented Mar 12, 2020

Describe the bug
If you store the value for a Input component in state (controlled-component) and set the value from another source than the Input component itself, through handleChange or as initial value, the value of the text field is not updated. With React Developer Tools the props on the component looks to be updated but not the state (see screenshot).

To Reproduce
Steps to reproduce the behavior:

  1. Put the value of the Input component in a state
  2. Set that state from somewhere else
  3. Watch as the value is not updated

Code example:

const [url, setUrl] = useState('defaultUrl')

return (
  <Input value={url} handleChange={(value) => setUrl(value)} />
  <Button onClick={() => setUrl('newUrl')} />
)

If you click the button the value in the text field is still 'defaultUrl'.

Expected behavior
The value (state) of the text field should be updated.

Screenshots
image

Additional context
This becomes a problem if you for example want a button that sets default values for inputs.

This is really just a visual bug but makes the user experience bad.

@mmj-ssb mmj-ssb changed the title Input - Updating value from another source Input - Updating value from other source Mar 12, 2020
@ssb-cgn
Copy link
Contributor

ssb-cgn commented Jun 4, 2020

Vi oppretter en sak på dette :)

@rsassb
Copy link

rsassb commented Sep 1, 2023

Har dere sett noe mer på denne saken, @ssb-cgn? Vi er flere som har behov for samme funksjonalitet :)

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

No branches or pull requests

3 participants