1- import React , { createContext , useContext } from "react" ;
1+ import React from "react" ;
22import type { ReactNode } from "react" ;
33import type { DetailedHTMLProps , AnchorHTMLAttributes } from "react" ;
44
@@ -8,40 +8,22 @@ type HTMLAnchorProps = DetailedHTMLProps<
88> ;
99
1010// eslint-disable-next-line @typescript-eslint/no-empty-interface
11- export interface RegisterLink {
12- // Link: typeof Link
13- }
11+ export interface RegisterLink { }
1412
1513export type RegisteredLinkProps = RegisterLink extends {
1614 Link : ( props : infer LinkProps ) => any ;
1715}
1816 ? Omit < LinkProps , "children" >
1917 : Omit < HTMLAnchorProps , "children" > ;
2018
21- const context = createContext < CreateLinkProviderPrams [ "Link" ] > ( props => < a { ...props } /> ) ;
22-
23- type CreateLinkProviderPrams = {
24- Link : ( props : RegisteredLinkProps & { children : ReactNode } ) => ReturnType < React . FC > ;
25- } ;
26-
27- export function createDsfrLinkProvider ( params : CreateLinkProviderPrams ) {
28- const { Link } = params ;
29-
30- type Props = {
31- children : ReactNode ;
32- } ;
19+ let Link : (
20+ props : RegisteredLinkProps & { children : ReactNode }
21+ ) => ReturnType < React . FC > = props => < a { ...props } /> ;
3322
34- function DsfrLinkProvider ( props : Props ) {
35- const { children } = props ;
36-
37- return < context . Provider value = { Link } > { children } </ context . Provider > ;
38- }
39-
40- return { DsfrLinkProvider } ;
23+ export function setLink ( params : { Link : typeof Link } ) : void {
24+ Link = params . Link ;
4125}
4226
43- export function useLink ( ) {
44- const Link = useContext ( context ) ;
45-
27+ export function getLink ( ) {
4628 return { Link } ;
4729}
0 commit comments