Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit 6940dcf

Browse files
author
X
authored
refactor: remove import component code in link.ts
1 parent c8cb02e commit 6940dcf

File tree

1 file changed

+0
-46
lines changed

1 file changed

+0
-46
lines changed

link.ts

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -130,49 +130,3 @@ export function NavLink(props: PropsWithChildren<NavLinkProps>) {
130130

131131
return React.createElement(Link, { ...rest, to })
132132
}
133-
134-
interface ImportProps {
135-
from: string
136-
name?: string // default is 'default'
137-
props?: Record<string, any>
138-
fallback?: ReactElement
139-
}
140-
141-
export function Import(props: ImportProps) {
142-
const { __importer, __sourceFile } = (props as any)
143-
const [error, setError] = useState<string | null>(null)
144-
const [mod, setMod] = useState<{ Component: ComponentType | null }>({ Component: null })
145-
146-
useEffect(() => {
147-
if (reModuleExt.test(__sourceFile)) {
148-
const p = util.splitPath(__importer)
149-
p.pop()
150-
import(util.cleanPath('/_aleph/' + p.join('/') + '/' + props.from))
151-
.then(mod => {
152-
const Component = mod[props.name || 'default']
153-
if (util.isLikelyReactComponent(Component)) {
154-
setMod({ Component })
155-
} else {
156-
setError(`component${props.name ? ` '${props.name}'` : ''} not found`)
157-
}
158-
})
159-
.catch((err: Error) => {
160-
setError(err.message)
161-
})
162-
}
163-
}, [__importer, __sourceFile])
164-
165-
if (error) {
166-
return React.createElement('div', { style: { color: 'red' } }, error)
167-
}
168-
169-
if (mod.Component) {
170-
return React.createElement(mod.Component, props.props)
171-
}
172-
173-
if (reModuleExt.test(__sourceFile) && props.fallback) {
174-
return props.fallback
175-
}
176-
177-
return null
178-
}

0 commit comments

Comments
 (0)