useViewTransitionState
Returns true when there is an active View Transition to the specified location. This can be used to apply finer-grained styles to elements to further customize the view transition.
Parameters
To
required
The location to check for an active View Transition. Can be a string path or a partial
Path object with pathname, search, and hash.object
"route" | "path"
default:"\"route\""
The relative routing type to use when resolving the
to location:"route"(default) - Relative to the route hierarchy"path"- Relative to the URL path segments
Return Value
boolean
true if there is an active View Transition to the specified location, otherwise false.Type Declaration
Usage Examples
Image Gallery Transitions
Animated List Items
Conditional Transition Styles
Multiple Transition Elements
Common Patterns
Shared Element Transitions
Dynamic Transition Names
Back Navigation Transitions
CSS Integration
Defining View Transitions
Complex Transitions
Requirements
-
View transitions must be enabled via the
viewTransitionprop on navigation: - Browser support - View Transitions API is not supported in all browsers
-
Must be used within RouterProvider from
react-router-dom
Browser Support
View Transitions are a modern web API with limited browser support. Check Can I Use for current browser compatibility. For unsupported browsers, the transition simply won’t occur, and navigation will work normally.Notes
- Available in Framework and Data modes only
- Must be used within
react-router-dom’sRouterProvider(not the one fromreact-router) - Returns
truefor both forward and backward transitions to the specified location - The
viewTransitionNameCSS property must be set for transitions to work - Each
viewTransitionNameshould be unique within the document - Transitions work bidirectionally (going to and coming from the location)
Related
<Link viewTransition>- Enable view transitions on links<Form viewTransition>- Enable view transitions on form submissionsuseNavigate- Navigate programmatically with view transitions- View Transitions API - MDN documentation