Skip to content

Commit

Permalink
clear location state after scrolling into view
Browse files Browse the repository at this point in the history
  • Loading branch information
Svenstar74 committed May 11, 2024
1 parent 1355b55 commit ae3b29e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/features/conversations/components/ConversationCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useRef, useState } from 'react';
import { useLocation } from 'react-router-dom';
import { useLocation, useNavigate } from 'react-router-dom';
import { Collapse, IconButton } from '@mui/material';
import EditIcon from '@mui/icons-material/Edit';
import DeleteIcon from '@mui/icons-material/Delete';
Expand All @@ -21,6 +21,7 @@ interface Props {
}

function ConversationCard({ conversationId, userBName, conversationState, onDeleteConversation }: Props) {
const navigate = useNavigate();
const location = useLocation();

const cardRef = useRef<HTMLDivElement>(null);
Expand All @@ -32,6 +33,7 @@ function ConversationCard({ conversationId, userBName, conversationState, onDele
useEffect(() => {
if (location.state?.id === conversationId && cardRef.current) {
cardRef.current.scrollIntoView({ behavior: 'smooth' });
navigate(location.pathname, { state: {} });
}
}, []);

Expand Down

0 comments on commit ae3b29e

Please sign in to comment.