I'm working on a reactjS PROJECT and I want To get the id of the selected item in a link to fetch the details. this is how I consume the api :
const [selectedComplain, setSelectedComplain] = useState([]);
async function getComplain(compl_id) {
setSelectedComplain(compl_id)
console.warn(compl_id)
let result = await fetch(`${API_ENDPOINT}/api/getComp/` + compl_id);
result = await result.json();
console.warn(result)
}
This is the Link part :
<Link to={`/complain/details/`} compl_id={selectedComplain}>
<span onClick={()=>getComplain(item.compl_id)}>
{item.compl_title}
</span>
</Link>
Thanks in advance for anyone will try to help me