I have the following modules structure:
/components
├── Button.js
├── Checkbox.js
├── index.js
├── DateSelect
├── DateSelect.js
└── index.js
With /components/DateSelect/index.js
:
import DateSelect from './DateSelect';
export default DateSelect;
/components/index.js
:
import DateSelect from './DateSelect';
import Button from './Button';
import Checkbox from './Checkbox';
export {
DateSelect,
Button,
Checkbox,
};
And /components/DateSelect/DateSelect.js
:
import { Checkbox } from '../';
// ...code
// I want to do this!
const MyCustomCheckbox = props => <Checkbox style={someStyle} />;
// ...code
class DateSelect extends React.Component {
// code
}
export default DateSelect;
Now, I want to access Checkbox
as in the code above, in the top level scope of the file, but I get undefined
. If I access this variable, however, in the render
method of DateSelect
, it works as expected.
I'm not completely sure on why this is the case, or how I can fix this (I can do import Checkbox from '../Checkbox'
, but I don't want to change the pattern of using the index.js
file of the directory), and I also want to understand exactly what's going on. Any ideas?