- All file names and folders should be in camelCase
- New pages should have their own folder under
src/pages/
e.x: I am creating a homepage. The.tsxfile would then be located here:src/pages/home/home.tsx. - Components should go under components folder.
-
Use single quotes for all quotes (JSX classNames, paths, etc, should be in double quotes)
-
If a single quote is neccessary in a string.
Context:console.log('Can't do this');Prefer template literals:
console.log(`Can't do this`);
Over double qoutes:
console.log("Don't do this");
- Consult Frontend team before adding new packages.
- This will help keep reduce unneccessary overhead for the repo.
- When installing a new package, check if there is a types package for it as well.
- Prefer named functions for anonymous callbacks
Prefer:
setTimeout(
function logUserEntry() {
console.log('...')
}
, 1000);
<br>
Over:
<br>
setTimeout(() => {
console.log('...');
}, 1000);
This will help readers of the code faster and better understand what the function is doing.
### This does not apply when you need lexical `this` behaviour. In this case, use arrow functions.
- Prefer function declarations over expressions
- POLE: Principle of Least Exposure
Each variable, function, etc. should have the least exposure as possible. Break up the code into blocks if variable will only be used in that block.
Prefer:
for(...) {
...
{
let temp; // temporary variable which is only used in this block.
}
...
}
Over:
for(...) {
...
let temp; // temporary variable which can be accessed throughout the entire for-loop.
...
}
- Variable declarations
- Prefer
letandconstovervar. - Use
constwhen a variable is not re-assigned.
- Prefer
- New Line at the end of a file
- Comments when neccessary.
- Spaces before opening curly brace ({) for functions and in CSS.
Prefer:function name() {}overfunction(){} - Conditional Rendering in JSX
Prefer:
{
condition ? <><> : <><>
}
Over: {condition ? <><> : <><>}
- Template literals, JSX classNames, etc.
Prefer:className={ name }&console.log(`${ name }`)Over:className={name}&console.log(`${name}`)
- For JSX return statements that take up more than one line (including return statement), please wrap the JSX in parentheses.
Prefer:
` return (...
);<br> Over: <br>return
...
;
`
- Prefer
<Component /> - Over
<Component/>
- Break up unrelated statements with whitespace.
- Please include screen-shots or videos of the changes you made (from the website).