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.

How to set initial value on screen load

See original GitHub issue

Hi, how to set value initial value on screen load, as below example, Need to set “BSNL” as default value

If data(items) is pulled from API, using useEffect and once data pulled successfully we set value to second last value like below example

const [open, setOpen] = useState(false);
const [value, setValue] = useState(null);
const [items, setItems] = useState([
        { value: 'Airtel', label: 'Airtel' },
        { value: 'BSNL', label: 'BSNL' },
        { value: 'VI', label: 'VI' }
    ]);
useEffect(() => {
//   data taken from api
  setItems(data);
}, []);

<DropDownPicker items={items} open={open} setOpen={setOpen} value={value} setValue={setValue} />

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
gessic-appscommented, Jun 8, 2021

@hossein-zare That deoesn’t seem to work for me…I set Value and it’s always showing as “select an item”

`

const [value, setValue] = useState('defaultValue');`


      <DropDownPicker
            style={defaultStyles.picker} 
            dropDownContainerStyle={defaultStyles.dropdownStyle}
            open={open}
            labelStyle={defaultStyles.dropDownLabels}
            listItemLabelStyle={defaultStyles.dropDownLabels}
            arrowIconStyle={{
                width: 20,
                height: 20,
              }}
            value={value}
            maxHeight={200}
            items={playerProfiles}
            searchable={false}
            setValue={updateProfile}
            // @ts-ignore
            setItems={setPlayerProfiles}
            // @ts-ignore
            setOpen={setOpen}
            />

`

1reaction
jjpeeradechcommented, Jul 4, 2021

try JSON.stringify for value image

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set default values for fields or controls - Microsoft Support
Right-click the control that you want to change, and then click Properties or press F4. Click the All tab in the property sheet,...
Read more >
Android Preferences: How to load the default values when the ...
I have set all the android:defaultValue="" for them. When I start my application, I need the preferences, or if they are not set...
Read more >
getting default values in module pool screen - SAP Community
Hi,. When you create the screen...jus double click on the field.There One option will be there : TEXT. There you can give your...
Read more >
Set Default Value of Epicor Fields With Screen Customization
The first step is to open the form you would like to set the default value in using developer mode. When you are...
Read more >
Set Default Values in Power Apps - SharePoint - YouTube
This video is a step-by-step tutorial on how to set the default values of controls in Power Apps. We will set default values...
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