I have a React form with Material-UI. I would like to get the id from the URL link using useParams and make some API requests in order to populate form-data:
http://localhost:3001/ticket-profile/9459377
Main app.tsx:
function App() {
return (
<Router>
<Navbar />
<Switch>
<Route path='/ticket-profile/:id' component={TicketProfile} />
</Switch>
</Router>
);
}
I use this code to open a new page and pass id param:
history.push(`/ticket-profile/${id}`)
I need to get the data into this page:
export default function TicketProfile(props: any) {
let { id } = useParams();
const [ticket, setTicket] = useState<TicketDTO[]>([]);
useEffect(() => {
getSingleTicket();
}, []);
const getSingleTicket = async () => {
getTicket(id)
.then((resp) => {
setTicket(resp.data);
}
But for this line let { id } I get:
TS2339: Property 'id' does not exist on type '{}'.
Do you know how I can fix this issue?