question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to lazy load components and use them in TSX?

See original GitHub issue
const LazyComp = () => import('@/LazyComp');

and somewhere below in render function:

<LazyComp />

Runtime is ok, but Typescript is not:

JSX element type 'Promise<typeof import("path/to/LazyComp")>' is not a constructor function for JSX elements.
  Type 'Promise<typeof import("path/to/LazyComp")>' is missing the following properties from type 'Element': isRootInsert, isComment

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
wonderful-pandacommented, May 15, 2019

Leave this issue opened until async component will be supported formally.

0reactions
nagaraja0yellapucommented, Feb 16, 2021

Marked in Bold is what helped me to achieve the same.

import(“./lib/select-list”).then((m) => m.default)

More details follows:

export function pretendNormalComponent<A extends Promise<typeof Vue>>(
  factory: () => A
): A extends Promise<infer V> ? V : never {
  return factory as any;
}

const EmployeeList = pretendNormalComponent(
  () => import("./lib/select-list").then((m) => m.default)
);
export { EmployeeList };

My Component look like

import Vue from "vue";
import { VNode } from "vue";
import Component from "vue-class-component";
import * as tsx from "vue-tsx-support";

@Component
export default class EmployeeList extends Vue{
  _tsx!: tsx.DeclareProps<
    tsx.PickProps<
      EmployeeList,
      | "store"
      | "label"
      | "rules"
    >
  >;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Lazy loading React components - LogRocket Blog
Using React.​​ React. lazy() makes it easy to create components that are loaded using dynamic import() but rendered like regular components. This ...
Read more >
Lazy loading React components with React.lazy
Take any component that you want to lazy load and change it to the following: - import MyComponent from './MyComponent'; + const MyComponent ......
Read more >
Using React.lazy with TypeScript - Stack Overflow
const ScreensProductList = lazy(() => import('./screens/Products/List'));. But the import('./screens/Products/List') part triggers a TypeScript ...
Read more >
Code-Splitting - React
The React.lazy function lets you render a dynamic import as a regular component. Before: import OtherComponent from './OtherComponent';. After:.
Read more >
Lazy-load a component in Angular without routing
What if we want to pass some values or listen to some events from our lazy loading component? We cannot use the familiar...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found