Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs SingleDatePicker在选择日期后不更新_Reactjs_React Dates - Fatal编程技术网

Reactjs SingleDatePicker在选择日期后不更新

Reactjs SingleDatePicker在选择日期后不更新,reactjs,react-dates,Reactjs,React Dates,我试图在react引导表中使用SingleDatePicker,但它似乎不起作用。下面是我的代码 class EOLEditor extends React.Component { constructor(props) { super(props); this.updateData = this.updateData.bind(this); this.state = { focused: null,

我试图在
react引导表中使用
SingleDatePicker
,但它似乎不起作用。下面是我的代码

class EOLEditor extends React.Component {

    constructor(props) {
        super(props);
        this.updateData = this.updateData.bind(this);
        this.state = {
                focused: null,
                name: props.defaultValue,
                open: true,
                expiry_date: (this.props.defaultValue !== null ) ? moment(this.props.defaultValue, 'DD-MMM-YY hh:mm:ss.SSSSSS A') : null
        }
    }

    componentWillReceiveProps(nextProps) {
        console.log(this.props);
        console.log(nextProps.defaultValue);

        if(this.props.defaultValue != nextProps.defaultValue){
            this.setState({expiry_date : moment(this.props.defaultValue, 'DD-MMM-YY hh:mm:ss.SSSSSS A')});
        }
    }
    /*focus() {
        console.log(this.refs);
        this.refs.inputRef.focus();
    }*/

    updateData() {
        console.log(this.props.row.id);

        console.log(this.state.expiry_date);
        this.props.onUpdate({ id: this.props.row.id, expiry_date: this.state.expiry_date });
    }
    close = () => {
        this.setState({ open: false });
        this.props.onUpdate(this.props.defaultValue);
    };

    render() {
        console.log(this);
        //const m_date = (this.props.defaultValue == '') ? null : moment(this.props.defaultValue, 'DD-MMM-YY hh:mm:ss.SSSSSS A');
        //console.log(this.props.defaultValue);
        //console.log(m_date);
        return (
                <SingleDatePicker
                date={this.state.expiry_date} // momentPropTypes.momentObj or null
                // onDateChange={date => this.setState({ date })} // PropTypes.func.isRequired
                onDateChange={(e) => {
                    console.log(e);
                        const e_after = (e == null) ? '' : e.format('DD-MMM-YY');
                        this.setState({ expiry_date: e_after });
                        //this.onAfterSaveCell({ target: { defaultValue: e_after } }, 'expiry_date');
                        this.updateData();
                    }
                }
                focused={this.state.focused} // PropTypes.bool
                onFocusChange={({ focused }) => { console.log(focused); this.setState({ focused }); }} // PropTypes.func.isRequired
                showClearDate
                small
                displayFormat="DD-MMM-YY"
                ref="inputRef"
            />
        );
    }    
}

在代码沙箱中复制问题会更好,请务必提及您正在使用的软件包的版本。
d: Thu Jul 18 2019 12:00:00 GMT+0100 (British Summer Time) {}
_f: "DD-MMM-YY hh:mm:ss.SSSSSS A"
_i: "31-DEC-18 12.00.00.000000 AM"
_isAMomentObject: true
_isUTC: false
_isValid: true
_locale: Locale {_calendar: {…}, _longDateFormat: {…}, _invalidDate: "Invalid date", ordinal: ƒ, _dayOfMonthOrdinalParse: /\d{1,2}(th|st|nd|rd)/, …}
_pf: {empty: false, unusedTokens: Array(0), unusedInput: Array(2), overflow: -1, charsLeftOver: 2, …}
__proto__: Object