D
D
dromist2022-01-23 14:57:29
React
dromist, 2022-01-23 14:57:29

TodoList filling form, it is impossible to display the edited text in the input, how to resolve the issue?

Good afternoon! I am creating a todo form in react and there is a text change button, but after changing the text it is not displayed in the input. Those. I can change the field itself, but after changing the new text is not displayed, I can’t understand what’s wrong, tell me, please.
Here is the code:

import React, {useState} from 'react';

export const TodoItem = ({ todo, onChange, remove, rename }) => {
const { id, completed, title } = todo;

const [isEdited, setIsEdited] = useState(false)
const [editText, setEditText] = useState(title)

const editItem = (id) =>{
setIsEdited(prev => !prev)
}

const onEdit = (e) => {
setEditText (e.target.value)
}

const edit = (id) => {
setIsEdited(prev => !prev)
}

return (


className="input__todo"
type="checkbox"
checked={completed}
onChange={() => onChange(id)}
/>
{isEdited
? value={editText}
type= "text"
onChange={onEdit}
onBlur={edit}
/>
: title
}


editItem(id)}/>
remove(id)} />


);
};

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question