I am faced with a challenge concerning my modal and form. I have successfully implemented a feature where clicking on an "Add" button opens the form within the modal. However, I now want to extend this functionality to include editing items created using the form when clicking on the div of a specific item.
My main struggle lies in determining when to render the "Add" items part versus the "Edit" items part in my application. Currently, I utilize context for the modal, which only has a default value of false. The modal opens successfully when either the button or item is clicked, but it defaults to the add form.
Below is the structure of my form:
const AddEditForm = () => {
const [list, setList] = useContext(DataContext)
const [modal, setModal] = useContext(DataContext2)
const { item, setItem, id, updatedItem, setUpdatedItem } =
useContext(DataContext3)
const [editForm, setEditForm] = useState(false)
const STATUS = ['-', 'todo', 'inProgress', 'done']
const USERS = ['-', 'Unassigned', 'JD', 'AJ', 'SS']
const toggleOnClick = () => {
addItem()
setModal(!modal)
}
const toggleOnClickEdit = () => {
UpdateItem()
setModal(!modal)
}
// Rest of the code remains the same...
}
I hope this solution can potentially benefit others facing a similar dilemma!