--- myst: html_meta: "description": "Add the Edit mode so that the user can edit the question and answer list." "property=og:description": "Add the Edit mode so that the user can edit the question and answer list." "property=og:title": "Use Initial Form Data To Edit An Item" "keywords": "Plone, training, exercise, solution, React" --- (initial-form-data-label)= # Use Initial Form Data To Edit An Item ## Two Modes For The FAQ Item We will use inline editing to edit an item. Create a button to switch to "edit" mode. This mode should be set in the state. Change the render method to show a form (similar to the "add" form) in "edit" mode, and the view we currently have in the "view" mode. The `onSave` handler can be a dummy handler for now. First we will focus on the two modes. ````{dropdown} Solution :animate: fade-in-slide-down :icon: question ```{code-block} jsx :emphasize-lines: 7,16-23,26-40,48,50-51 :linenos: true import { useState } from "react"; import "./FaqItem.css"; import PropTypes from "prop-types"; const FaqItem = (props) => { const [isAnswer, setAnswer] = useState(false); const [isEditMode, setIsEditMode] = useState(false); const toggle = () => { setAnswer(!isAnswer); }; const ondelete = () => { props.onDelete(props.index); }; const onEdit = () => { setIsEditMode(true); }; const onSave = (e) => { e.preventDefault(); setIsEditMode(false); }; return ( <> {isEditMode ? (