-
Notifications
You must be signed in to change notification settings - Fork 286
Code styleguide
Tim Stirrat edited this page May 2, 2020
·
9 revisions
Use constants for numbers
- arr.slice(0, 14);
+ arr.slice(0, MAX_EXPOSURE_DAYS);
Named exports have slightly better developer ergonomics in IDEs. The IDE can read the named export in files across the project even if you have not imported it before. Imports will always use consistent names. Names can be overridden with as
, if needed.
Default exports are not easily discovered and lead to inconsistent names.
export const myVar = 1234;
export class MyClass {}
export const MyComponent = () => {
return <View />;
}
This will clearly express inputs and outputs. JSDoc comments will help the IDE infer types.
/**
* @param {{
* navigation: Navigation;
* label: string;
* }} param0
*/
export const MyComponent = ({navigation, label}) => {
return <View onPress={...}>{label}</View>;
}
<View>
- {getSpecialViewStuff(label, color)}
+ <SpecialViewStuff label={label} color={color} />
</View>