Now, create the component's file. Again, following our conventions, we will use lower-kebab-case. Create a file called search.tsx under frontend/src/components.
Next, add the following basic structure for the component:
import React, { useEffect } from 'react'; import Container from 'react-bootstrap/Container'; type Props = { }; export const Search = (props: Props) => { useEffect(() => { console.log('Search component rendered'); }); return ( <Container className='lf-search'> TODO add content here </Container> ); };
For now, the component is just an empty shell, but you can already add it to the Home page.
Open the frontend/src/pages/home.tsx file and do the following:
- Import the Search component using import { Search } from '../components/search';.
- Replace the JSX code in the page with <Search />.
In the next subsections, we will wrap our search input and button within the React Bootstrap Container element.
We will proceed in multiple steps:
- First, we will add the components we need inside of the container.
- Then, we'll define the state of our component and bind our input to it.
- After that, we will define handlers for the different events.
- Finally, we will define some props so that our component can communicate with its clients.
This process is roughly inspired by the following article: https://reactjs.org/docs/thinking-in-react.html.