I've got a dropdown, and setValue to setValue of value to the selection of the dropdown. I've also got a text element that should display the value whenever the dropdown is changed, but when I change the dropdown it doesn't update the Text and it stays blank? This is the dropdown I am using https://www.npmjs.com/package/react-native-element-dropdown
const App = () => {
const [products, setProducts] = useState<ProductType[] | []>([]);
const [open, setOpen] = useState(false);
const [value, setValue] = useState(' ');
const [isFocus, setIsFocus] = useState(false);
const getProducts = async () => {
try {
const response = await axios.get('http://192.168.1.32:3000/api/products');
setProducts(response.data);
} catch (error) {
// handle error
alert('no');
}
};
React.useEffect(() => {
getProducts();
}, []);
return (
<>
<AppBar
title="App"
trailing={props => (
<Button
variant="text"
title="ADD"
compact
//onPress={getProducts}
style={{marginEnd: 4}}
{...props}
/>
)}
/>
<Dropdown
style={[styles.dropdown, isFocus && {borderColor: 'blue'}]}
data={products}
search
maxHeight={300}
labelField="product"
valueField="aisle"
placeholder={!isFocus ? 'Select item' : '...'}
searchPlaceholder="Search..."
value={value}
onFocus={() => setIsFocus(true)}
onBlur={() => setIsFocus(false)}
onChange={item => {
setValue(item.value);
setIsFocus(false);
}}
/>
<TextInput label="quantity" variant="standard" />
<Text>value: {value}</Text>
</>
);
};
export default App;
const styles = StyleSheet.create({
dropdown: {
height: 50,
borderColor: 'gray',
borderWidth: 0.5,
borderRadius: 8,
paddingHorizontal: 8,
},
row: {
flexDirection: 'row',
flexWrap: 'wrap',
},
});