I tried toggling the alarm button to check button for the targeted task but the alarm icon of all the tasks change too. Am using the redux toolkit
This is my state
const initialState = {
isHideForm: false,
taskDesc: "",
date: "",
time: "",
user: "",
taskTitle: "",
isEditing: false,
editID: null,
isCompleted: false,
data: [],
};
Here is the reducer for toggling the button
completed(state, action) {
let item = state.data.find((x) => x.id === action.payload);
if (item) {
state.isCompleted = !state.isCompleted;
}
},
This is the on-click button
<button onClick={(e) => handleCompleted(e, d.id)}
className="border-y-2 border-r-2 border-gray-200 p-2 rounded-r">
{isCompleted ? <GrCheckmark /> : <FaBell />}
</button>
You've to return a new state object
if(item) {
return {...state, isCompleted: !state.isCompleted }
}