Issue with the type of dynamic imports for React components

Imagine having a dynamic import of a component named PersonalDetailsForm within a multi-step registration component called RegistrationFormSteps.

During the loading process of PersonalDetailsForm, there is a need to access its nested component known as PersonalDetailsForm.Loading to display the loading state.

PersonalDetailsForm.Loading.

const PersonalDetailsForm = () => <h1>Test</h1>;
const PersonalDetailsFormLoader = () => {
  return <>loading...</>;
};

PersonalDetailsForm.Loading = PersonalDetailsFormLoader;
export default PersonalDetailsForm

This component is then imported into the RegistrationFormSteps Component

const PersonalDetailsForm = dynamic(() => import("./personal-details-form"), {
  ssr: false,
  loading: () => <PersonalDetailsForm.Loading />,
});

const loaders = [<TypeSelectionForm.Loading />, <PersonalDetailsForm.Loading />];

In both scenarios, an error message appears:

 
Property 'Loading' does not exist on type 'ComponentType<{}>'.
Property 'Loading' does not exist on type 'ComponentClass<{}, any>'. 

UPDATE

The error only arises when components are imported dynamically. Regular imports allow successful referencing of the <Loading/> nested component.

Answer №1

After reviewing your code, it appears that you are trying to display a component based on the current status. To achieve this functionality according to the provided status, you can use the following implementation.

 import React from "react";    
const PersonalDetailsForm = ({ status }) => {
      const PersonalDetailsFormLoader = () => <div>Loading...</div>;
      const PersonalDetailsFormError = () => <div>Error occurred!</div>;
      const PersonalDetailsFormSuccess = () => <div>Success!</div>;
    
      const components = {
        loading: <PersonalDetailsFormLoader />,
        error: <PersonalDetailsFormError />,
        success: <PersonalDetailsFormSuccess />,
      };
    
      return <div>{components[status]}</div>;
    };
    
    export default PersonalDetailsForm;

You can include the above component in your RegistrationFormSteps as shown below.

<PersonalDetailsForm status={"loading"} />

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a feature in Nextjs similar to the Javascript window.onload function that ensures a webpage is fully loaded before being displayed?

Using JavaScript, I can easily utilize the window onload function to ensure that the web page is displayed only after everything has finished loading. This feature is incredibly valuable to me because it ensures that elements such as pictures and fonts are ...

Comparison of URL parameter with property in a filtered array - Next.js/JavaScript

Utilizing Nextjs/Javascript for my project, I am working on filtering the name property within each object of an array based on a comparison function's outcome. However, I have doubts about whether I am approaching this correctly. My current approach ...

Receive notification indicating that the function is of void type

As a newcomer to angular, I am currently in the process of setting up my authorization module for an ionic project I am developing. I have made significant progress, but I have encountered an issue with the 'auth' service that I created. Within ...

Connecting one page to another on the same page using Next.js

Hey everyone, I could really use some help with linking pages on Next.js. I understand how to create links, but here's what I'm trying to achieve: On my homepage, I have navigation links for courses, team, and contact in the navbar. When I click ...

Updating the state of Formik

Currently, I'm knee-deep in a React project that requires a slew of calculations. To manage my forms, I've turned to Formik, and for extra utility functions, I've enlisted the help of lodash. Here's a peek at a snippet of my code: impor ...

Ways to access the req.user object within services

After implementing an authentication middleware in NestJs as shown below: @Injectable() export class AuthenticationMiddleware implements NestMiddleware { constructor() {} async use(req: any, res: any, next: () => void) { const a ...

Transform ECMAScript Observable / Zen Observable into RXJS Observable

I currently have an ECMAScript Observable that is compliant with specifications, specifically sourced from the wonka library. I am facing challenges in converting this type of observable to an rxjs 6 observable. It appears that this conversion was possibl ...

Troubleshooting Error in Converting a JSX File with Tailwind CSS and Typescript

I found a code example on the Tailwind website. However, when I changed the file extension to .tsx, I encountered an error related to the className attribute. Do I need to specify a type for the className variable? What steps should I take to resolve thi ...

Jest: Test fails due to import statement in node_module dependency

Short Version I'm experiencing a crash in my Jest test due to a SyntaxError related to an import statement outside a module. The issue arises from a node_module that uses the import statement. How can I resolve this error? Situation Overview In deve ...

Guide to generating a dropdown menu and linking it with data received from a server

I am completely new to Angular and recently received a project involving it. My task is to create a nested dropdown list for Json data retrieved from a server using Rest Api calls. The data contains a Level attribute that indicates the hierarchy level of ...

The 'string[]' type cannot be assigned to the 'string | ParsedUrlQueryInput | null | undefined' type in Next.js and Typescript

I'm facing an issue while attempting to transfer an array of strings from one page to another in Next.js using <Link href={{ pathname: "/model", query: data }}>. The problem arises when the query parameter is red underlined: Type &apos ...

Assistance with Optimizing TypeScript - "The depth of type instantiation is overly excessive, potentially leading to an infinite loop. (Error code:

I'm currently working on extracting data- attributes from a complete object of element attributes using TypeScript code. However, I've encountered an error message stating "Type instantiation is excessively deep and possibly infinite (2589)." It ...

Different methods to efficiently import directives into multiple components without repeating the code

As I delve into creating Web apps using Angular2 with TypeScript, one aspect that stands out is the need to import CustomElements (such as Components and Directives, Validators) in each individual Component file. This results in repetitive code like direct ...

Anonymous function's return type

Looking for advice on an anonymous function I've written: static oneOf(options: any[], cb?: Function) ValidatorFn { .... } I'm a TypeScript beginner and unsure how to specify that the 'cb' must return a boolean. Can this be done, an ...

To effectively manage the form, I must carefully monitor any modifications and update the SAVE button accordingly in an Angular application

Are you experiencing an issue with detecting any changes on a page, where there is some information displayed and even if no changes are present, the SAVE button remains active for clicking? ngOnInit(): void { this.createConfigForm() th ...

Angular2 has encountered a malfunction with the chart feature

My attempt to create a Bar Chart with this GitHub repository is not working in Chrome. You can view my code on Plunker. Can someone help me identify the issue? Below is the updated code: app.ts import {Component, Pipe, PipeTransform} from 'angular2 ...

Deliver the commitment to the data source connection settings in TypeORM

Is it possible to retrieve the datasource connection options from AWS Parameter Store instead of storing them as environment variables in a general JavaScript question? I am having difficulty finding a solution and seeking expert advice on this matter. Th ...

Exploring Polymorphism in Typescript through Data Model Interfaces

Seeking out a design pattern for the following scenario: IApp.ts export interface IApp { platform: PlatformEnum; version: string; islive: boolean; title: string; iconurl: string; } IAppleApp.ts export interface IAppleApp extends IApp { ...

What could be the reason for tsc providing such confusing error messages upon revealing transitive implementation types?

In my project, I am dealing with a node module A that relies on another node module B, both of which are written in Typescript. Module B uses bluebird as its Promise implementation and returns Promises to module A. While module B has typings for bluebird, ...

Tips for enabling custom object properties in Chrome DevTools

In my typescript class, I am utilizing a Proxy to intercept and dispatch on get and set operations. The functionality is working smoothly and I have successfully enabled auto-completion in vscode for these properties. However, when I switch to the chrome d ...