React 无限循环中的可重用组件

Reusable Component in React Infinite Loop

我正在尝试制作一个 "adds an employee" 具有反应的虚拟项目。 我使用了带有 bulma css 的表单和一个输入组件作为此表单的可重用组件。当我 运行 npm 启动时,它编译成功但页面从未加载,而且我的代码中似乎有一个无限循环。谁能看看代码并让我知道我做错了什么?

import React, { Component } from 'react'
import Input from './input'

class EmployeeGeneral extends Component {
 state = {
   Employee: { FirstName: '', LastName: '', MeliCode: '' }
 }

 handleSubmit = e => {
   e.preventDefault()
 }

 handleChange = ({ currentTarget: input }) => {
   const Employee = { ...this.state.Employee }
   Employee[input.name] = input.value
   this.setState({ Employee })
 }
 render() {
   const { Employee } = this.state

   return (
     <main className="container">
       <h1 className="title">Employee General</h1>
       <form onSubmit={this.handleSubmit}>
         <div className="columns">
           <div className="column">
             <Input
               name="firstName"
               label="First Name"
               value={Employee.FirstName}
               onChange={this.handleChange}
             />

             <div className="control">
               <button className="button is-primary">Add Employee</button>
             </div>
           </div>
           <div className="column">
             <Input
               name="lastName"
               label="Last Name"
               value={Employee.LastName}
               onChange={this.handleChange}
             />
           </div>
           <div className="column">
             <Input
               name="meliCode "
               label="Meli Code"
               value={Employee.MeliCode}
               onChange={this.handleChange}
             />
           </div>
         </div>
       </form>
     </main>
   )
 }
}

export default EmployeeGeneral

import React from 'react'

const Input = ({ name, label, onChange, value }) => {
  return (
    <div className="field">
      <label htmlFor={name} className="label">
        {label}
      </label>
      <div className="control">
        <Input
          value={value}
          onChange={onChange}
          autoFocus
          id={name}
          type="text"
          className="input"
          placeholder={label}
          name={name}
        />
      </div>
      <p className="help">{label}</p>
    </div>
  )
}

export default Input

您正在递归使用 Input 组件。将内部 Input 更改为常规 input

const Input = ({ name, label, onChange, value }) => {
  return (
    <div className="field">
      <label htmlFor={name} className="label">
        {label}
      </label>
      <div className="control">
        <input
          value={value}
          onChange={onChange}
          autoFocus
          id={name}
          type="text"
          className="input"
          placeholder={label}
          name={name}
        />
      </div>
      <p className="help">{label}</p>
    </div>
  )
}