alert
, confirm
and prompt
JS-0052 52
53 // Function deleting a single project
54 const deleteProject = ( { iD }: ProjectInterface) => {
55 if (confirm('Are you sure you want to delete that?\nThis is an irreversible operation\nProject ToDos will be deleted as well.')) { 56 const projectsCopy = [...projects];
57 const toDosCopy = [...toDoList];
58 const newProjectsCopy = projectsCopy.filter(x => x.iD !== iD);
64
65 // Function deleting a single done project
66 const deleteDoneProject = ( { iD }: ProjectInterface) => {
67 if (confirm('Are you sure you want to delete that?\nThis is an irreversible operation\nProject ToDos will be deleted as well.')) { 68 const doneProjectsCopy = [...doneProjects]
69 const doneToDosCopy = [...doneToDos]
70 const newDoneProjectsCopy = doneProjectsCopy.filter(x => x.iD !== iD)
40
41 // Function for deleting a single ToDo element
42 const deleteToDo = (iD: number) => {
43 if (confirm('Are you sure you want to delete that?\n(This is an irreversible operation)')) {44 const toDosCopy = [...toDoList].filter(x => x.iD !== iD);
45 dispatch(setToDos(toDosCopy));
46 }
15 // Function to delete a signle done ToDo
16 const deleteToDo = ( { iD }:ToDoInterface ) => {
17
18 if (confirm('Are you sure you want to delete that?\n(This is an irreversible operation)')) {19 const doneToDosCopy = [...doneToDos].filter(x => x.iD !== iD);
20
21 dispatch(setDoneList(doneToDosCopy));
32 updateProfile(user, {
33 displayName: name
34 }).then(() => {
35 alert("User registered successfully");36 }).catch((error) => {
37 // An error occurred
38 // ...
JavaScript's alert
, confirm
and prompt
functions are widely considered to be obtrusive as UI elements and should be replaced by a more appropriate custom UI implementation.
Furthermore, alert
is often used while debugging code, which should be removed before deployment to production.
alert("here!");
confirm("Are you sure?");
prompt("What is your name?", "John Doe");
customAlert("Something happened!");
customConfirm("Are you sure?");
customPrompt("Who are you?");
function foo() {
const alert = myCustomLib.customAlert;
alert();
}