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
if you don't want to use redux, you need to get the Other value from props and initialize the value on the picker. Regards
Only with redux I would do this:
I would create a reducer reasons
In this reducer I would initialize values and the selecteddefault and I would create an action CHANGE_SLECTEd to change the value selected.
and in the component I would call the reducer, I called Dashboard.
inthis form you are not using local state and everything is immediately update to redux.
I hope this info will help you... Regards