7

Below is my react components structure (Using TypeScript):

-App.tsx

  -NewRequestForm.tsx

    -EmployeeInfo.tsx

    -AssetInfo.tsx

I am trying to import EmployeeInfo & AssetInfo in NewRequestForm, but while using import statement both components are not visible, but I can see Prop & States interfaces.

enter image description here

Please suggest how child components can be imported in my NewFormRequest.tsx

AssetInfo.tsx (child1)

import * as React from 'react';

export interface AssetInfoProps {}
export interface AssetInfoState {}

export default class AssetInfo extends React.Component<AssetInfoProps, 
AssetInfoState> {
  constructor(props: AssetInfoProps) {
    super(props);

    this.state = {};
  }

  public render() {
    return <div />;
  }
}

EmployeeInfo.tsx (Child2)

import * as React from 'react';

export interface EmployeeInfoProps {}
export interface EmployeeInfoState {}

export default class EmployeeInfo extends React.Component<EmployeeInfoProps, 
EmployeeInfoState> {
  constructor(props: EmployeeInfoProps) {
    super(props);

    this.state = {};
  }

  public render() {
    return <div />;
  }
}

NewRequestForm.tsx (Parent)

import * as React from 'react';
import {} from './EmployeeInfo';
import {} from './AssetInfo';

export interface NewRequestFormProps {}

export default class NewRequestForm extends 
React.Component<NewRequestFormProps, any> {
  public render() {
    return <div />;
  }
}

1 Answer 1

7

Remove the default keyword for exporting the EmployeeInfo

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Murat, It worked. Any explanation behind removing 'default' keyword ?
@SandeepNandey You would import a default export without {}, but you can read more here stackoverflow.com/a/33307487/4467208

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.