Skip to content

Commit

Permalink
Fix initExpanded being incorrectly handled
Browse files Browse the repository at this point in the history
  • Loading branch information
ankith26 committed Dec 15, 2024
1 parent db4d709 commit fb7adbc
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions frontend/src/components/ReviewBox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const Review = ({ review, endpoint, onUpdate }) => {

const ReviewBox = ({ children, title, endpoint, initExpanded }) => {
const [reviewsList, setReviewsList] = useState(null);
const [isExpanded, setIsExpanded] = useState(initExpanded);
const [isExpanded, setIsExpanded] = useState(false);
const cache = useRef({}); // Cache for reviews data

const fetchReviews = async () => {
Expand All @@ -138,6 +138,11 @@ const ReviewBox = ({ children, title, endpoint, initExpanded }) => {
setIsExpanded(!isExpanded);
};

/* init expanded when endpoint changes */
useEffect(() => {
setIsExpanded(initExpanded);
}, [endpoint]);

useEffect(() => {
if (isExpanded) {
if (cache.current[endpoint]) {
Expand All @@ -148,7 +153,7 @@ const ReviewBox = ({ children, title, endpoint, initExpanded }) => {
} else {
setReviewsList(null);
}
}, [endpoint, isExpanded]);
}, [isExpanded]);

return (
<Card
Expand Down

0 comments on commit fb7adbc

Please sign in to comment.