This exact structure suggests that, for example, the Editable
component would have everything about that component inside Editable.jsx
. and I mean that your component code stays inside that file.
Now what's index for ? Inside index you would simply do something like this:
import Editable from './Editable.jsx';
export default Editable;
and that's it. This is helpful because inside other components or containers you can do this:
import Editable from '../Editable';
because it tries to access the index.js
file by default thus not requiring any more info from you. It would import automatically the index.js
file which imports the actual component itself. If you did not have an index.js
file you would have had to do this:
import Editable from '../Editable/Editable';
which is kind of awkward. I don't like to have an index file that all it does is import a component and export it. What I usually do is just have all my component code inside the index.js
file without the need of the Editable.jsx
at all. That's up to you so feel free to take the approach you like better.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…