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.

defaultValue not working?

See original GitHub issue

How can I set a default value in the picker? What I want is after the screen/component loads, there should be a value in the dropdown (without the user clicking the picker)

I have already tried setting a defaultValue props but it does not work.

const [defValue, setDefValue] = useState({ label: 'test', value: 'test'})

            <DropDownPicker
                listMode="SCROLLVIEW"
                scrollViewProps={{
                  nestedScrollEnabled: true,
                }}
                zIndex={3000}
                zIndexInverse={1000}
                style={styles.field}
                open={open2}
                value={value}
                items={leaveOptionDropDown}
                setOpen={setOpen2}
                setValue={setValue}
                defaultValue={defValue}
                onChangeValue={(value) => {
                  handleChange('type_of_leave')
                  setFieldValue('type_of_leave', value)
                }}
            />

I have also tried setting a selected value in the items but it also does not work.

        leaveOptionDropDown.push({
          key: item.id,
          label:item..first_name+" "+item.last_name,
          value:item.id,
          selected: {selected}
        })

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
hossein-zarecommented, May 11, 2022

You must pass a value not an object.

const [items, setItems] = useState([
  {label: 'United States', value: 'US'},
  {label: 'Russia', value: 'RU'}
]);
const [value, setValue] = useState(null);

useEffect(() => {
  setValue('RU');
}, []);

OR

const [value, setValue] = useState('RU');
0reactions
Ashutosh-Tiwaricommented, Dec 30, 2022

How to achieve this default value behavior for class component?

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - DefaultValue attribute is not working with my Auto Property
The DefaultValue attribute is only used to tell the Visual Studio Designers (for example when designing a form) what the default value of...
Read more >
DefaultValue not working | Optimizely Developer Community
Hello everyone. In a Block a [DefaultValue] is not working. It is an existing Block, existing properties [DefaultValue] is working fine.
Read more >
Default value not working - WordPress.org
Hi – I have an optional custom field, “job type”, on a set of pages for which I am trying to set a...
Read more >
Default value not work properly #2095 - GitHub
While I use mapstruct, I found the bug: For example: @Mapper(componentModel = "spring") public interface ExceptionMapper { @Mappings({ ...
Read more >
CheckBoxPreference default value not working [36914268]
setDefaultValues() seems to work when setting default vaues to true, but attempting to set a false as a default value doesn't create the...
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