React-Native v0.20.0^
Question regarding intended behavior for the IOSPicker component.
The picker component assumes that its children are all React elements and does not do any sort of check when attempting to read children properties.
Source code I'm referring to:
ReactChildren.forEach(props.children, function (child, index) {
if (child.props.value === props.selectedValue) {
selectedIndex = index;
}
items.push({value: child.props.value, label: child.props.label});
});
The important thing to look at is child.props.value -- this assumes that a child element has a props property and checks its value which will throw an error if props doesn't exist.
This prevents us from performing lazy evaluations on Picker children:
<Picker ...>
{someFalseCondition &&
<Picker.Item label="conditionalOption" value="0" />
}
<Picker.Item label="option1" value="1" />
<Picker.Item label="option2" value="2" />
...
</Picker>
Since someFalseCondition will return false, we end up with:
<Picker ...>
{false}
<Picker.Item label="option1" value="1" />
<Picker.Item label="option2" value="2" />
...
</Picker>
Which will throw an error since the Picker component assumes all of the children have properties.
Is this intended behavior? Seems like a bug to me.. I feel like we should be able to do things like this. If this is a bug, I'll gladly make a PR to fix this issue.
RN playground example

React-Native v0.20.0^
Question regarding intended behavior for the
IOSPickercomponent.The picker component assumes that its children are all React elements and does not do any sort of check when attempting to read children properties.
Source code I'm referring to:
The important thing to look at is
child.props.value-- this assumes that a child element has apropsproperty and checks its value which will throw an error ifpropsdoesn't exist.This prevents us from performing lazy evaluations on
Pickerchildren:Since
someFalseConditionwill returnfalse, we end up with:Which will throw an error since the
Pickercomponent assumes all of the children have properties.Is this intended behavior? Seems like a bug to me.. I feel like we should be able to do things like this. If this is a bug, I'll gladly make a PR to fix this issue.
RN playground example