-
Notifications
You must be signed in to change notification settings - Fork 115
Description
Hello!
A bit of a noob here but I need some help: I have a switch selector working, except that I need to set the initial state based on possibly preexisting props. I have a prop I'm modifying with the switch-selector component and that's working just fine. But I need to be able to pass that prop to the switch-selector component to determine its initial state when the app is reading in data.
I'm able to change the props using the SwitchSelector, wired all the way back down to the database, but I cannot set the initial state of the Switchselector based on props since the Switchselector's initial props only take a number and the prop is boolean. So, how do I pass a boolean prop down to the initial prop of the switch selector component?
The error I get is:
undefined is not an object (evaluating 'options[selected].activeColor')
I was trying to set initial based on the props like so:
initial={() => { if(this.props.item.collection) { return 1 } return 0 }
Here's my entire SwitchSelector component (it works if I just put in {-1} or {1} for the initial value.
<SwitchSelector {...this.props} style={{paddingTop: 10}} textColor='#9C9C9C' selectedColor='#FFFFFF' buttonColor='#65A5F6' borderColor='#DFDFDF' hasPadding animationDuration={250} buttonMargin={0} borderRadius={25} textStyle={{ fontSize: 12, }} selectedTextStyle={{ fontWeight: '800', fontSize: 12, }} height={45} initial={() => { if(this.props.item.collection) { return 1 } return 0 } } options={[ { label: "First label", value: false }, { label: "Second Label", value: true } ]} onPress={(value) => { this.props.updateField( { field: 'collection', value: value } )}} />
THanks very much!