Having issues with state and TRPC serverside component -> Like button on zustand
I am really struggling to get the correct state when refreshing the page. If i leave the page and navigate back to it, the state is always correct. But if i refresh the page the state is always set to false and not in sync with what's currently in my store.
I believe it has something to do with the serverside helpers and the id of my post not being available on the reloads. Has anyone come across this behaviour.
it's basically forcing me to do this
const { likedPosts, addLikedPost, removeLikedPost } = useLikeStore();
const [isLiked, setIsLiked] = useState(false);
useEffect(() => {
setIsLiked(likedPosts.includes(id));
}, [id, likedPosts]);
which cannot be correct. the likePosts.includeds(id) should be responsible for the state. I should have to use the one state to check the other state.
0 Replies