我有一个Picker
这样的组件:
const reasons = [
{ name: 'A' },
{ name: 'B' },
{ name: 'Other' }
];
<Picker
selectedValue={state.reasonSelected}
onValueChange={value => {
changeTransactionReason(value);
}}
>
{reasons.map((reason, key) => (
<Picker.Item
key={key}
label={reason.name}
value={reason.name}
/>
))}
</Picker>
Then, I need to render an Input
component only if the item "Other" is picked.
我可以 setState 该值,然后询问是否:
{state.itemSelected === 'Other' && (
<Input onChangeText={text => { reduxActionToSaveValue(text) }}/>
)}
但我不想混合本地状态和redux。这些值将存储在 redux 上,但是
如何在不丢失实际值的情况下比较“其他”值?所以我想知道是否有办法Picker
在不设置本地状态的情况下获取所选值