为什么:无法读取未定义的属性“电子邮件”?反应域

时间:2018-12-22 23:30:33

标签: reactjs react-dom

我需要在其他组件中使用状态,我用类似的道具发送了状态。

好的,这是我的./HandleForm容器。

import React, { PureComponent } from "react";

import NotLoggedRegisterForm from "./NotLoggedRegisterForm";

export default class HandleForm extends PureComponent {
  state = {
    data: {
      email: "",
      password: "",
      confirmPassword: ""
    }
  };

  handleChange = e => {
    this.setState({ ...this.state.data, [e.target.name]: e.target.value });
  };

  render() {
    return (
      <div>
        <NotLoggedRegisterForm data={this.state.data} />
      </div>
    );
  }
}

这是接收道具的一部分。

const { data } = props.data;

<Input
        prefix={<Icon type="mail" style={{ color: "rgba(0,0,0,.25)" }} />}
        type="email"
        placeholder="Email"
        name="email"
        onChange={props.handleChange}
        value={data.email}
      />

我收到该错误代码:

TypeError
Cannot read property 'email' of undefined
NotLoggedRegisterForm
/src/pages/logged/not/registerForm/NotLoggedRegisterForm.js:38:24
  35 |       placeholder="Email"
  36 |       name="email"
  37 |       onChange={props.handleChange}
> 38 |       value={data.email}
     |                  ^
  39 |     />
  40 |   )}
  41 | </FormItem>

2 个答案:

答案 0 :(得分:0)

更改

const { data } = props.data;

进入

const { data } = props;

答案 1 :(得分:0)

在您的代码中

from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC link = "replace_with_above_link" driver = webdriver.Chrome() wait = WebDriverWait(driver, 10) driver.get(link) [driver.execute_script("arguments[0].click();",item) for item in wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR,"tr.Iec")))] for elem in wait.until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR,".IecAttachments li a[href$='.pdf']"))): print(elem.get_attribute("href")) driver.quit() 是错误的。

因为const { data } = props.data包含props,而data不包含props.data,所以您可能会这样更改。

data