如何将DatepickerIOS日期对象传递给Firebase(React Native)

时间:2019-03-14 04:20:59

标签: react-native

我对编码非常陌生,并且上了Grinder的React Native课程。我不知道如何将datepickerios日期对象保存到Firebase。我很确定这里的代码中有错误。

任何帮助将不胜感激。另外,如果有人在寻找实习生,我将感谢您的帮助。谢谢!

class ScoreForm extends Component {

    constructor(props) {
        super(props);
        this.state = {chosenDate: new Date()};

        this.setDate = this.setDate.bind(this);
      }

      setDate(newDate) {
        this.setState({chosenDate: newDate});
      }

    render() {
        return (
            <View>
            <CardSection>
                    <Text style={styles.pickerTextStyle}>Enter Date</Text>
                 </CardSection>

                <CardSection>
                    {/* <Input
                        label="Date"
                        placeholder="MM/DD/YY"
                        value={this.props.date}
                        onChangeText={value => this.props.scoreUpdate({ prop: 'date', value })}
                    /> */}

                    <DatePickerIOS
                        style={{ flex: 1 }}
                        mode='date'
                        date={this.state.chosenDate}
                        onDateChange={value => this.props.scoreUpdate({ prop: 'date', value })}
                    />
                </CardSection>

                <CardSection>
                    <Input 
                        label="Score"
                        placeholder="Add Number"
                        value={this.props.score}
                        onChangeText={value => this.props.scoreUpdate({ prop: 'score', value })}
                    />                    
                </CardSection>
            </View>
        );
     }
    }

    const styles = {
      pickerTextStyle: {
        fontSize: 18,
        paddingLeft: 20
      }
    };

       const mapStateToProps = (state) => {
       const { date, score } = state.scoreForm;

       return { date, score };
     };

    export default connect(null, { scoreUpdate }) (ScoreForm);

由于我正在使用Redux,所以我假设我不想将其存储在状态中,对吗?这是this.props.ScoreUpdate操作:

export const scoreUpdate = ({ prop, value }) => {
    return {
        type: SCORE_UPDATE,
        payload: { prop, value }
    };
};

0 个答案:

没有答案