README.md44 lines · main
1# Writing components
2
3## Where to create your components
4
5- For components that declare the general structure and layout of a page:
6 - `/components/layouts/xxx`
7- For components that are tightly coupled to a specific interface:
8 - `/components/interfaces/xxx`
9- For components that are meant to be reusable across multiple pages:
10 - `/components/ui/xxx`
11- Note: We're gradually moving files out of the `to-be-cleaned` folder into the respective folders as we refactor
12
13## Component structure
14
15- If a component has constants and utility methods that are tightly coupled to itself, keep them close to the component and enclose them in a folder with an `index.tsx` as an entry point
16- Otherwise it can just be a file on its own
17- For example:
18 - ```
19 components/ui
20 - SampleComponentA
21 - SampleComponentA.tsx
22 - SampleComponentA.constants.ts
23 - SampleComponentA.utils.ts
24 - SampleComponentA.types.ts
25 - index.ts
26 - SampleComponentB.tsx
27 ```
28
29## Template for building components
30
31```ts
32
33// Declare the prop types of your component
34interface ComponentAProps {
35 sampleProp: string
36}
37
38// Name your component accordingly
39const ComponentA = ({ sampleProp }: ComponentAProps) => {
40 return <div>ComponentA: {sampleProp}</div>
41}
42
43export default ComponentA
44```
Preview

Writing components

Where to create your components

  • For components that declare the general structure and layout of a page:
    • /components/layouts/xxx
  • For components that are tightly coupled to a specific interface:
    • /components/interfaces/xxx
  • For components that are meant to be reusable across multiple pages:
    • /components/ui/xxx
  • Note: We're gradually moving files out of the to-be-cleaned folder into the respective folders as we refactor

Component structure

  • If a component has constants and utility methods that are tightly coupled to itself, keep them close to the component and enclose them in a folder with an index.tsx as an entry point
  • Otherwise it can just be a file on its own
  • For example:
    • components/ui
      - SampleComponentA
        - SampleComponentA.tsx
        - SampleComponentA.constants.ts
        - SampleComponentA.utils.ts
        - SampleComponentA.types.ts
        - index.ts
      - SampleComponentB.tsx
      

Template for building components


// Declare the prop types of your component
interface ComponentAProps {
  sampleProp: string
}

// Name your component accordingly
const ComponentA = ({ sampleProp }: ComponentAProps) => {
  return <div>ComponentA: {sampleProp}</div>
}

export default ComponentA