React-TypeScript: How to import component?
React-TypeScript: How to import component?
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.
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
Remove the default
keyword for exporting the EmployeeInfo
default
EmployeeInfo
@SandeepNandey You would import a default export without
{}
, but you can read more here stackoverflow.com/a/33307487/4467208– Murat K.
2 mins ago
{}
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Thanks Murat, It worked. Any explanation behind removing 'default' keyword ?
– Sandeep Nandey
3 mins ago