简体   繁体   English

我的输入在React中不起作用,onChange看起来也不错

[英]My input is not working in React, onChange looks good too

My input element doesn't let me type into it, it will show up, with the value i want, but I cannot delete or edit anything in the input. 我的输入元素不允许我输入,它会显示出来,并带有我想要的值,但我无法删除或编辑输入中的任何内容。 Everything is spelled correctly from what I have seen. 从我所见,一切都拼写正确。

I've been googling and have searched multiple SO forms, none have been able to help me. 我一直在使用Google搜索并且搜索了多个SO表格,但没有一个能够帮助我。 Which is why I am asking now 这就是为什么我现在问

const GuestName =(props)=>{
    if(props.isEditing){
        return(
        <form>
        <input type='text' className='edit-guest-input'
         value={props.guestName} onChange={e => props.editGuest(e.target.value)}/>
         </form>
        )
    }

    return (
    <span>{props.guestName}</span>
    )
}

the above is the input that will not work 以上是无效的输入

  editGuest=(id, name)=>{
    this.setState({
      guest: this.state.guest.map((guest) =>{
        if(id===guest.id){
          return{
            ...guest,
            name
          }}
          return guest
      })
    })
  }

this is the code for the onChange event. 这是onChange事件的代码。

const GuestList =(props)=>

    <div>

        <ul>
            {props.guest.filter( guest => !props.filterUnconfirmedGuest || guest.isConfirmed)
            .map((guest, index) =>   <Guest 
                            key={index}
                            guestName={guest.guestName}
                            toggleGuestConfirmed={props.toggleGuestConfirmed}
                            isConfirmed={guest.isConfirmed}
                            toggleEditGuest={()=> props.toggleEditGuest(guest.id)}
                            isEditing={guest.isEditing}
                            editGuest={editedName=> props.editGuest(editedName, guest.id)}
                            removeGuest={()=> props.removeGuest(guest.id)}
                                />)}
       </ul>
    </div>

The first argument is passed in here 第一个参数在这里传递

Probably a minor issue that I am too tired to notice lol. 可能是一个小问题,我太累了,无法注意到大声笑。 Any help is appreciated, thank you for your time! 感谢您的帮助,感谢您的宝贵时间!

You are calling the editGuests function with one argument 您正在用一个参数调用editGuests函数

onChange={e => props.editGuest(e.target.value)}

But it has two arguments in the definition 但是在定义中有两个参数

editGuest=(id, name)=>{

}

我认为在editGuest它应该是guestName: name :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM