Creating function-based components
In this section, we are going to start by creating a component for the header of our app, which will contain our app name and the ability to search for questions. Then, we'll implement some components so that we can start to build the home page of the app, along with some mock data.
Creating a Header component
We can create a basic Header
component and reference it within our App
component by carrying out the following steps:
- Create a new file called
Header.tsx
in thesrc
folder. - Import
React
into the file with the followingimport
statement:import React from 'react';
We need to import
React
because, as we learned at the start of this chapter, JSX is transpiled into JavaScriptReact.createElement
statements. So, withoutReact
, these statements will error out. - Our component is just going to render the word
header
initially...