A hook to create a link to a state.
This hook returns link (anchor tag) props for a given state reference. The resulting props can be spread onto an anchor tag.
The props returned from this hook are:
href
: the browser URL of the referenced stateonClick
: a mouse event handler that will active the referenced stateExample:
function HomeLink() {
const sref = useSref('home');
return <a {...sref}>Home</a>
}
Example:
function UserLink({ userId, username }) {
const sref = useSref('users.user', { userId: userId });
return <a {...sref}>{username}</a>
}
The onClick
handler falls back to native browser behavior (does not initiate a state transition) when:
<a target="_blank">Open in new window</a>
<a onClick={e => e.preventDefault()}>no-op</a>
The name of the state to link to
Any parameter values
Transition options used when the onClick handler fires.
Generated using TypeDoc