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.

Select component does not update when "defaultValue" changes.

See original GitHub issue

I’m using a select dropdown with a dynamic defaultValue prop. When the value supplied to defaultValue changes, but the rendered select dropdown still shows the previous defaultValue. My component is uncontrolled.

<Select defaultValue={ data.default }>
  {
    data.options.map(option => (
      <Option value={ option }> { option } </Option>
     ))
   }
</Select>
  

Antd version 2.5.2

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
yesmeckcommented, Dec 23, 2016

@pastelsky You should use value. Try learning controlled/uncontrolled component concept in React.

2reactions
pastelskycommented, Dec 23, 2016

To anyone facing a similar issue, do read https://github.com/facebook/react/issues/4101 . React dropdowns have this slightly confusing behaviour and the only way to force re-render without making it a controlled component is by introducing a “key= {defaultValue}”

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-select not showing default value and not updating
You're setting the Select value to form.natureOfTheRequest , so you need to update that specific field on its onChange callback, ...
Read more >
Re-render DefaultValue when Value Changes in React
React will never update the input tag if the value passed to defaultValue changes. It was meant to be a default/starting value only,...
Read more >
How to set default value in select using ReactJS
Following are the two approaches to set default value in select using ReactJS: Approach 1: Without using React Select component.
Read more >
Component prop not changing when select value changes ...
Component prop not changing when select value changes · Test that a component does not render when passed a certain prop value with...
Read more >
Element: <oj-select-single> - Oracle
Examples of actions are - creating a component, user changing the ... If there are no errors, then the value property is updated...
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