I've tried to get the id from the URL (with props.match.params.id) and pass it into a variable to reuse it. But props is undefined. I don't know why.
Anyone can see if I've done something wrong?
import React, { useState, useEffect } from "react";
import axios from "axios";
export default function Recipes() {
const [recipes, setRecipes] = useState([]);
useEffect(() => {
const id = props.match.params.id;
const getRecipes = async () => {
const url = `http://localhost:8000/user/recipes/${id}`;
const result = await axios.get(url);
setRecipes(result.data);
console.log("test", recipes);
};
getRecipes();
}, []);
return (
<div>
{recipes.map(recipe => (
<p>{recipe.title}</p>
))}
</div>
);
}