Advertisement

TrimwebsolutionsTrimwebsolutions

Problem and Solutions

How to keep the last component styles in react.js ?

By M.K. Verma · 2 May 2022

How to keep the last component styles in react.js ?

Your problem is in position of your delete button, that wrapped by div with makrComplete handler, so then you click on your delete button, markComplete fired too, so your isComplete changed and styles deleted. To prevent this behavor, you can do a little trick with prevent default. So, try to wrap your deleteTaskHandler in another function like that:

const deleteButtonClickHandler = (e) => {
    e.preventDefault();
    e.stopPropagation();

    deleteTaskHandler(id)
}

and your delete button makrdown should be look like this:

<button onClick={deleteButtonClickHandler}> Delete </button>