Как получить значение сборщиков материалов в компоненте? - PullRequest
0 голосов
/ 13 июня 2018

Вкл. Выбор даты из средства выбора даты, как получить значение в компоненте

Демонстрационная ссылка : https://material -ui.com / demos / pickers /

1-й пример

import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import TextField from '@material-ui/core/TextField';

const styles = theme => ({
  container: {
    display: 'flex',
    flexWrap: 'wrap',
  },
  textField: {
    marginLeft: theme.spacing.unit,
    marginRight: theme.spacing.unit,
    width: 200,
  },
});

function DatePickers(props) {
  const { classes } = props;

  return (
    <form className={classes.container} noValidate>
      <TextField
        id="date"
        label="Birthday"
        type="date"
        defaultValue="2017-05-24"
        className={classes.textField}
        InputLabelProps={{
          shrink: true,
        }}
      />
    </form>
  );
}

DatePickers.propTypes = {
  classes: PropTypes.object.isRequired,
};

export default withStyles(styles)(DatePickers);

Заранее спасибо

1 Ответ

0 голосов
/ 13 июня 2018

см. Документ API здесь: https://material -ui.com / api / text-field /

export default class App extends PureComponent {
  state = {
    value: ""
  };

  render() {
    const { value } = this.state;

    return (
      <div>
        <TextField
          id="date"
          label="Birthday"
          type="date"
          defaultValue="2017-05-24"
          InputLabelProps={{
            shrink: true
          }}
          onChange={event => {
            this.setState({ value: event.target.value });
          }}
        />
        {value}
      </div>
    );
  }
}

и пример здесь: https://codesandbox.io/s/3rp5zl971

надеюсь, что это поможет вам

...