Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/CookTime/client-app/src/components/Recipe/RecipePage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';
import { Alert, Row, Toast, ToastContainer } from 'react-bootstrap';
import { RecipeProvider, useRecipeContext } from './RecipeContext';
import { RecipeHeader } from './RecipeHeader';
Expand Down Expand Up @@ -82,6 +82,13 @@ function RecipePageContent({ recipeId }: { recipeId: string }) {
}

export function RecipePage({ recipeId, generatedRecipe }: RecipePageProps) {
// Navigating between recipes (e.g. tapping a recommended recipe) keeps the same
// /recipes/details pathname and only changes the ?id= query, so the router does
// not scroll. Reset the scroll position whenever the recipe changes.
useEffect(() => {
window.scrollTo(0, 0);
}, [recipeId]);

return (
<RecipeProvider recipeId={recipeId} generatedRecipe={generatedRecipe}>
<RecipePageContent recipeId={recipeId} />
Expand Down
Loading