The repository for Trysts web application. Writing in Typescript with ReactJs 18
- Component name must be
Capitalize
- Prevent export component as
default
- For simple component, type/interface should be define inside component file
- For complex type/interface, define in specific file inside
models
folder (create if needed) - If any type is recognize by intellisense or basic type, no need to define them again
- For constant variable, define it in
constants.ts
insidelibs
folder - Props drill maximum 3 levels
- Use
semantic tag
as much as posible
To create new component, follow these several steps:
- Create new component folder
- Create
index.ts
file (this file will export all of the additional components that use to build our component) - Create
<component_name>.tsx
file (this file will contain our component code)
Example:
// Folder structure
├── src
│ ├── components
│ │ ├── ColorPicker
│ │ │ ├── index.ts
│ │ │ ├── ColorPicker.tsx
│ │ │ └── ColorItem.tsx
// ColorItem.tsx
type ColorItemProps = {
colorName: 'red' | 'green'
onColorChange: () => void
}
export const ColorItem: React.FC<ColorItemProps> = ({ colorName, onColorChange }) => {
return <div color={colorName} onClick={onColorChange} />
}
// ColorPicker.tsx
import { ColorItem } from './ColorItem'
export const ColorPicker = () => {
return (
<div>
<ColorItem colorName="red" onColorChange={() => {}} />
</div>
)
}
// index.ts
export * from './ColorItem'
export * from './ColorPicker'
import { ColorPicker } from '@/components/ColorPicker'
- Use the imperative, present tense: "change" not "changed" nor "changes"
- Don't capitalize the first letter
- No dot (.) at the end
- (optinal) Icon added for funny purpose (maximum 1 icon)
git commit -m "<prefix>: <message>"
init
: Project initiation and configsfeat
: A new featurefix
: A bug fixrefactor
: A code change that neither fixes a bug nor adds a featureperf
: A code change that improves performancechore
: Very tiny fix, ex: typo, color
Example:
git commit -m "fix: add pivotal emojis to readme 🌈"