11import React , { createContext , useContext } from "react" ;
22import type { ReactNode } from "react" ;
3- import { assert } from "tsafe/assert" ;
43import type { DetailedHTMLProps , AnchorHTMLAttributes } from "react" ;
54
65type HTMLAnchorProps = DetailedHTMLProps <
@@ -17,14 +16,12 @@ export type RegisteredLinkProps = RegisterLink extends {
1716 Link : ( props : infer LinkProps ) => any ;
1817}
1918 ? Omit < LinkProps , "children" >
20- : RegisterLink extends { Link : "a" }
21- ? Omit < HTMLAnchorProps , "children" >
22- : React . AriaAttributes & { className ?: string } ;
19+ : Omit < HTMLAnchorProps , "children" > ;
2320
24- const context = createContext < CreateLinkProviderPrams [ "Link" ] | undefined > ( undefined ) ;
21+ const context = createContext < CreateLinkProviderPrams [ "Link" ] > ( props => < a { ... props } /> ) ;
2522
2623type CreateLinkProviderPrams = {
27- Link : ( ( props : RegisteredLinkProps & { children : ReactNode } ) => ReturnType < React . FC > ) | "a" ;
24+ Link : ( props : RegisteredLinkProps & { children : ReactNode } ) => ReturnType < React . FC > ;
2825} ;
2926
3027export function createDsfrLinkProvider ( params : CreateLinkProviderPrams ) {
@@ -44,16 +41,7 @@ export function createDsfrLinkProvider(params: CreateLinkProviderPrams) {
4441}
4542
4643export function useLink ( ) {
47- let Link = useContext ( context ) ;
48-
49- assert (
50- Link !== undefined ,
51- "You need to specify what routing library is in use in your project, see: https://react-dsfr.etalab.studio/routing"
52- ) ;
53-
54- if ( Link === "a" ) {
55- Link = props => < a { ...props } /> ;
56- }
44+ const Link = useContext ( context ) ;
5745
5846 return { Link } ;
5947}
0 commit comments