Reputation: 9185
I have 3 files, which use the same import statements each:
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Dimensions, Keyboard, SectionList, Text, TextInput, TouchableOpacity, View } from 'react-native';
import { Entypo, EvilIcons } from 'react-native-vector-icons';
How could I condense this code in each page to only have 1 line:
import AllImports from './filename';
And the 'filename' file should probably contain all these imports and one export, but I am not sure how to implement it.
Upvotes: 1
Views: 76
Reputation: 8781
You should not. DRY is a good practice, but it isn't an iron law. Sometimes you have no other option than repeating yourself, other times it's better to repeat yourself.
This is the latter case. Having imports be explicit in each module makes it really easy to find what dependencies each component has. With an intermediate module, you'd have to check that module to see what's happening. Also, there's no guarantee things'll stay like this forever. At some point the components will have different requirements, and you're likely to get into a situation where you're depending on more than you need.
For the few lines you're saving, all the disadvantages aren't worth it.
Upvotes: 8