直接定义导入组件,并且在从index.js文件导入时定义

时间:2019-03-06 17:00:46

标签: reactjs

我遇到了一个奇怪的问题。直接从Input导入../Input组件是在defined之外的TestComponent,但是,从'../index'文件导入Input的是not defined在{{1}之外}

TestComponent

输入-> index.js

import Input from '../Input';
import { Input as Input2 } from '../index';

console.log(Input, Input2) //Input2 is undefined, whereas Input is defined

const { Search } = Input;
const { Search: Search2 } = Input2 // gives reading property Search of Undefined

const TestComponent = (props) => {
   return (
      <Search/>
      <Input2.Search/> // is working
    )
}

index.js

import Search from './Search';

const Input = (props) => {
  return (<input value={props.value} />)
}

Input.Search = Search;
export default Input;

请有人帮助我了解此问题。

0 个答案:

没有答案