Using redux, you should use a useEffect on local component, it is the easier way to avoid bugs (do not add any ref in your store).
xxxxxxxxxx
const { selectedPost } = useSelector(selectPostsState);
useEffect(() => {
if (!selectedPost) {
return;
}
const ref = window.document.getElementById(
postIdPrefix + selectedPost.id
);
if (!ref) {
return;
}
ref.scrollIntoView({ behavior: "smooth", block: "center" });
}, [selectedPost]);