From 6ccc79d2794f00f8c5695af4bf6b6c4fa5723f20 Mon Sep 17 00:00:00 2001 From: Lory-Stan TANASI Date: Sat, 31 Aug 2024 18:48:04 +0200 Subject: [PATCH] feat(recipe): load recipe data every time --- screens/recipe/RecipeScreen.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/screens/recipe/RecipeScreen.tsx b/screens/recipe/RecipeScreen.tsx index df2c84e..2ec1216 100644 --- a/screens/recipe/RecipeScreen.tsx +++ b/screens/recipe/RecipeScreen.tsx @@ -23,7 +23,7 @@ export default function RecipeScreen({ navigation, route }: Props) { const [isDeleting, setIsDeleting] = useState(false) useEffect(() => { - const fetchRecipe = async () => { + const unsubscribe = navigation.addListener('focus', async () => { const recipe = await RecipeModel.findById(route.params.id) .populate<{ author: Model }>('author') @@ -38,10 +38,10 @@ export default function RecipeScreen({ navigation, route }: Props) { setRecipe(recipe) setServings(recipe.servings) - } + }) - fetchRecipe() - }, [route.params.id]) + return unsubscribe + }, [navigation, route.params.id]) if (!recipe) { return (