Skip to content

Instantly share code, notes, and snippets.

@jspw
Last active July 5, 2024 16:50
Show Gist options
  • Select an option

  • Save jspw/b4ff03281dbc89cd5a7266b5e30eeab1 to your computer and use it in GitHub Desktop.

Select an option

Save jspw/b4ff03281dbc89cd5a7266b5e30eeab1 to your computer and use it in GitHub Desktop.

Revisions

  1. jspw renamed this gist Jul 5, 2024. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. jspw renamed this gist Jul 5, 2024. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions Convention.md → Code-Convention.md
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@

    ## JavaScript



    ## React

    @@ -31,7 +31,7 @@

    ### Low Level Code

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

    Example:

  3. jspw created this gist Jul 5, 2024.
    98 changes: 98 additions & 0 deletions Convention.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,98 @@
    # 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:

    ```ts

    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