Skip to content

Instantly share code, notes, and snippets.

@jspw
Last active July 5, 2024 16:50
Show Gist options
  • Save jspw/b4ff03281dbc89cd5a7266b5e30eeab1 to your computer and use it in GitHub Desktop.
Save jspw/b4ff03281dbc89cd5a7266b5e30eeab1 to your computer and use it in GitHub Desktop.
Code Convention

Code Conventions

Java

Springboot

JavaScript

React

Filename related

  • React Component files -> .tsx

  • All other files such as interface, utility, constant files -> .ts

  • React Component’s naming convention -> SampleComponent.tsx

  • Normal typescript file naming convention -> sampleFile.ts

Low Level Code

  • Inside a react component ---> define variables -> define states -> define methods/functions -> hooks (useMemo() -> useEffect())

    Example:

export const SampleComponent = () => { 

// variables 

const totalPages = 2; 

 

//states 

const [count, setCount] = useState<number>(0) 

const [result, setResult] = useState(0) 

const [height, setHeight] = useState(0) 

const [width, setWidth] = useState(0) 

 

// methods 

const handleCountIncrease = () => setCount(pre => pre + 1) 

const handleCountDecrease = () => setCount(pre => pre - 1) 

 

const area = (height: number, width: number) => { 

setResult(2 * height * width) 

} 

 

//hooks 

 

const renderData = useMemo(() => <div>Area : {result}</div>, [result]) 

 

useEffect(() => { 

area(height, width) 

}, [height, width]) 

 

return renderData 

} 

ExpressJs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment