How to set a default value when loading?
See original GitHub issueHi,
I’ve a drop down component which I need to set a default value when the component loads, so I can use that value to call the API first time. How can I achieve this? My code is as follows.
const branches = useSelector(state => state.userData.branches);
const [open, setOpen] = useState(false);
const [value, setValue] = useState(null);
const [items, setItems] = useState([]);
useFocusEffect(
React.useCallback(() => {
const _branch = branches.map(x => {
return {
label: x.name,
value: x.id,
};
});
setItems(_branch);
getCartData()
}, []),
);
async function getCartData() {
console.log(value) // I need the default value here once the component mounts
}
<DropDownPicker
open={open}
value={value}
items={items}
itemKey={item => item.id}
setOpen={setOpen}
setValue={setValue}
setItems={setItems}
placeholder="Select Branch"
style={{
borderColor: 'white',
marginVertical: '2%',
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.23,
shadowRadius: 2.62,
elevation: 4,
}}
dropDownContainerStyle={{
borderColor: 'grey',
}}
/>
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Set default values for fields or controls - Microsoft Support
Set a default value · In the Navigation Pane, right-click the table that you want to change, and then click Design View. ·...
Read more >3 Ways to Set Default Value in JavaScript | SamanthaMing.com
Let's break down the 3 different ways to set Default Values using logical operator, ternary, and if/else...
Read more >how to set default value in data loading function? — oracle-tech
I have created a data loading in APEX, and want to record who load the data. so I created one column named user_created....
Read more >Loading and Applying Default Values - MicroStrategy
To do this, click the Preferences link, then click the Project defaults link on the left-hand side of the page (under the "Preferences...
Read more >Assigning default index values - IBM
To have the load process assign a default from the Load Information tab or by using propagation, you must specify the _*USELOADDEFAULTORPROPAGATION*_ default...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@premdasvm Sorry i’m a bit busy. I’ll check it’s behavior.
What about setting a default value in useState? And also in your example there are two “items” states, I guess one of them should be the “open” state?