Files organisation
There are 2 important concepts with our React app: pages andcomponents.
Pages
Each folder correspond to a URL and contains everything the page needs.
Example /links displays all the links saved by a user.
.
βββ src
βββ pages
Β Β Β Β βββ links
Β Β Β Β βββ Link.tsx
Β Β Β Β βββ LinkList.tsx
Β Β Β Β βββ index.tsxLink.tsxis responsible for display the link's information:
import * as React from "react";
export interface LinkProps {
id: string;
uri: string;
userId: string;
}
export const Link = (props: LinkProps) => <div>URI: {props.uri}</div>;and LinkList.tsx display them as a list:
Then LinksPage.ts fetches the data and uses the created components to display it:
Link and LinkList are components but to keep it simple, we keep things related to each other close to each other. This prevent files juggling when editing a page.
If we use Link in more than one page, then we will move it to thecomponents folder.
Components
This folder containers all components that are used in more that one place. Let's add a Header to our LinksPage.
Replace everything in App.tsx
Run yarn start and open localhost:3000.

Last updated
Was this helpful?