i am building an Management app where one is assignee and other is user ( complainer, who makes complaint ). Both assignee and complainer have their own dashboards. i want to implement that when complainer makes new complaint, it will be displayed on assignee dashboard without reloading the page. i have implemented this but this gives me that error.
can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
i have tried many times but still this error.
import React, { createContext, useState, useEffect } from "react";
import http from "../services/httpService";
import { getAssigneeComplaints } from "../services/complaintService";
import config from "../config.json";
export const ComplaintContext = createContext();
const ComplaintContextProvider = props => {
const [assigneeComplaints, setAssigneeComplaints] = useState([]);
// getting all assignee complaints
const getAssigneeComplaint = async () => {
const { data } = await getAssigneeComplaints();
setAssigneeComplaints(data);
console.log(data);
};
// saving a complaint
const saveComplaint = async complaint => {
console.log("new complaint is being saved");
await http.post(config.apiUrl + "/complainer-complaints", complaint);
getAssigneeComplaint();
};
useEffect(() => {
getAssigneeComplaint();
}, []);
return (
<>
<ComplaintContext.Provider
value={{
getAssigneeComplaint,
assigneeComplaints,
saveComplaint
}}
>
{props.children}
</ComplaintContext.Provider>
</>
);
};
export default ComplaintContextProvider;
i expect to show the complaint on assignee's dashbaord without reloading the page.