Skip to content

How to use view transitions with laravel and react? #2235

Answered by Saad5400
Saad5400 asked this question in Help
Discussion options

You must be logged in to vote

I guess I've solved my own issue like this: (IDK why but delay makes it work)

import React, { useEffect } from 'react';
import { router } from '@inertiajs/react';

export default function DefaultLayout({ children }: { children: React.ReactNode }) {
    useEffect(() => {
        if (!document.startViewTransition) return;

        // When a navigation is triggered...
        const handleNavigate = (e: CustomEvent) => {

            // Skip non-GET requests.
            if (e.detail.visit.method !== 'get') return;

            // Start the view transition.
            document.startViewTransition(async () => {
                await new Promise<void>((resolve) => {

                    // Com…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Saad5400
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
1 participant