获取高阶组件中的输入值

Get input value in higher order component

我在高阶组件中提取输入值 onChange 时遇到问题。

我想为我的 contactFormData 对象属性分配输入值。

代码:

export default withReflex()(ContactForm)
function ContactForm() {
  let contactFormData = {
    subject: '',
    email: '',
    message: '',
  }
  return (
    <Section style={styles.container}>
      <SectionTitle>
        Contact Us
      </SectionTitle>
      <SectionSubtitle>
        And let&apos;s code together
      </SectionSubtitle>

        <Flex col={12} justify="center" wrap style={{ margin: 'auto' }}>

          <Flex p={2} col={12} md={6}>
            <input
              style={styles.input}
              type="text" name="subject"
              placeholder="Subject"
              onChange={(subjectInput) => contactFormData.subject = subjectInput}
              required
            />
          </Flex>

          <Flex p={2} col={12} md={6}>
            <input
              style={styles.input}
              type="email"
              name="from"
              placeholder="Email"
              onChange={(emailInput) => contactFormData.email = emailInput}
              required />
          </Flex>

          <Flex p={2} col={12}>
            <textarea
              style={{ ...styles.input, height: 250 }}
              placeholder="Message"
              name="body"
              onChange={(messageInput) => contactFormData.message = messageInput}
              required
            />
          </Flex>

          <Flex p={2} col={12} justify="center">
            <Button
              typeStyle="primary"
              style={{ width: '100%' }}
              onClick={sendContactMail}
            >
              SEND THE MESSAGE
            </Button>
          </Flex>
        </Flex>
    </Section>
  )
  function sendContactMail() {
    console.log(contactFormData);
  }
}

当我 console.log 我的对象时,所有值都是 "proxy" 预期值

控制台:

使用

onChange={(event) => contactFormData.subject = event.target.value;