#Link Component blocking server actions call ?

3 messages ยท Page 1 of 1 (latest)

dusk narwhalBOT
#

๐Ÿ”Ž This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

๐Ÿ•ต๏ธ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

โœ… You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

fast arch
#

Link Component blocking server actions call ?

#
async function fetchWishes(wishlistId: string) {
    const response = await getAllWishes(wishlistId); // Server actions blocking ??
    if (!response.isSuccessful) {
        toast({...});
        return [];
    }

    return response.data;
}


export default function WishesList({ wishlistId }: WishesListProps) {
    const [loading, setLoading] = useState<boolean>(true);
    const [wishes, setWishes] = useState<TWish[]>([]);

    useEffect(() => {
        const fetchData = async () => {
            try {
                // call to the blocking function
                const fetchedWishes = await fetchWishes(wishlistId); 
                setWishes(fetchedWishes);
            } catch (error) {
                toast({...});
            } finally {
                setLoading(false);
            }
        };

        fetchData();
    }, []);

        return (
             <>    
               {!loading ? (
                  wishes?.length > 0 ? (
                    wishes.map((wish) => (...)
                   ) : (
                     <div className="...">
                        <p className="...">
                          Start adding wishes now! ๐ŸŒŸ
                        </p>
                      </div> 
                   )
              ) : (
                 <SkeletonPage />
                )}
             </>
        )
}

The first Picture is when I use the Link to navigate between my routes, the setLoading(false) is never set cause the server actions is called but is indefinitely waiting