index.ts file in each folder that lists the components/screens in each folder. It will list each component/screen as named exports, which can be imported on one line. This is the same syntax we use to import components, such as View and Text from ‘react-native’. For example, import { View, Text } from 'react-native'.
Add index file to components folder
First we will create anindex.ts for the components folder.
- In the
componentsfolder and create a new file calledindex.ts. We use the.tsextension, because this is a pure TypeScript file that doesn’t contain any JSX.
- Open
index.tsand add import statements for every component in thecomponentsfolder. - Add an export statement that lists each component.
index.ts file should look like this:
Import components
Next, we need to updateLandingScreen.tsx to use the new imports approach.
- In the
LandingScreen.tsxremove the import statements for Header and VideoCard. - Add one import statement that adds the components from
index.ts. Note that we only need to specify the import from thecomponentsfolder, as theindex.tsfile will be read in this folder to find the named exports (Header, VideoCard).
LandingScreen.tsx should look like this:
Add index file to screens folder
Now we will repeat the process for thescreens folder.
- Create a file called
index.tsin thescreensfolder.
- Open
index.tsand add import statements for every component in thescreensfolder. - Add an export statement that lists each component.
index.ts file should look like this:
Import screens
Now we need to update the import statements inApp.tsx.
- Open
App.tsx. - Remove the import statement for LandingScreen.
- Add one import statement that adds the LandingScreen screen from the
screensfolder.
App.tsx should now look like this:
- Reload the app and verify that everything renders the same.

