Define the header component
Let’s start by creating the Header component.- From VS Code, open the folder for the basic demo app we just created in the Setup module.
- Within the
srcfolder create a folder calledcomponents. This folder may already exist in the template, in which case delete its contents. - Within
componentscreate a file calledHeader.tsx, as follows:
- Open
Header.tsxand import React (see code below). We need to import React, as the JSX we will write will be converted into React Components using JSX transformer. - Import the components needed from react-native in order to build our header. We will need a StyleSheet, a Text component, and a View component.
- Declare a functional component called “Header” - you can do this as an arrow function or by declaring it as a function (We use arrow functions throughout this guide).
- Return a View component, that contains a Text component with the welcome message, “Welcome to Vega!”
export const MyComponent = () => {};. However, default exports are usually used when the exported component is only going to be imported once, or if a file exports one thing (further reading).
- Add the export statement below:
Header.tsxcode should now look like this:
Add Styling
Now that we have our first component we can add styling to it. StyleSheet is an abstraction similar to CSS StyleSheets. Unlike CSS, you can’t cascade a style across elements of the same type. For example, if you have a element in separate files that have the same styling, you have to create a StyleSheet and define the style in each file.- After the Header arrow function, create a new StyleSheet called
styleswithheaderContainerandheaderTextsections.
headerContainer style centers the text component and fills the width of the screen. The headerText style changes the size, weight, and color of the text. Besides a hex code, you can also set the color to an RGB value (e.g. rgb(50, 50, 50)), or a named color (e.g. ‘gray’).
- Add the
headerContainerstyle to the View element, and theheaderTextstyle to the Text element.
Header.tsx code should look like this:
Render the header component
In order to render our Header component, we need to import it intoApp.tsx.
- In
App.tsxmodify the imports to import the Header component instead of the link. - Remove the Text, ImageBackground and Image imports.
- Render the Header in a View with the style prop container.
- Modify the StyleSheet to only have the container stying which is just giving our app a nicer background color.
App.tsx should look like this:
- Now head over to the simulator to see what our header looks like!

New header
- If you are using the VegaStudio, use the Vega Extension to press the play button next to your app name.
- If you are using the CLI, in the terminal running the metro server, press ‘r’.

