I have a Picker component like this:
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.
I could setState that value and then ask if:
{state.itemSelected === 'Other' && (
<Input onChangeText={text => { reduxActionToSaveValue(text) }}/>
)}
But I don't want to mix local state and redux. The values will be stored on redux, but
How can I compare the value 'Other' without losing it actual value? So I want to know if there's a way with Picker to get the selected value without setting local states
Why not compare the value directly with redux? if you are using react-redux you can map the value where selected item is stored using mapStateToProps (here is the documentation) and if you are directly using redux you can still do it. then once the action of choosing other has dispatched and the value is set your input will show.