-
Notifications
You must be signed in to change notification settings - Fork 7
Whitespaces, trailing commas and semi colons
Kato Charles edited this page May 27, 2019
·
1 revision
- After leading a parenthesis, in functions and conditionals.
if (a == b) {
return true;
}
handleAction = (event) => {
return event;
}
if (a == b) {
return true;
} else {
return false;
}
- In curly braces.
const data = { admin: 'true' };
import { Component } from 'react';
- For long method chains
const filteredUsers = this.state.usersWithRoles
.filter(user => user.name.toLowerCase()
.includes(value.toLowerCase()));
- After adding a single line comment
// import third party libraries
import { Button } from 'react-toolbox';
-
Leave whitespace after blocks (as shown in 1 above)
-
No whitespaces inside brackets[] or parenthesis()
- Writing objects, function parameters, imports, and arrays in block
import {
Autocomplete,
Button,
Dropdown,
Snackbar,
} from 'react-toolbox';
this.state = {
filteredUsers: [],
roles: [],
searchValue: '',
showModal: false,
usersWithRoles: [],
};
const usersWithRoles = [
'Admin',
'Admin2',
'Admin3',
];
const saveRole(
userId,
roleId,
currentRole,
) {
// function code
}
-
After variable declaration
let users = [];
-
After expressions
- Examples are return statements, function calls, immediately invoked function expressions, etcetera
users.map(user => {
return user;
}
alert("Hello world");
// IIFE
(function(){...A...})();
public handleToggle = () => {
this.setState({ showModal : !this.state.showModal });
};
For more visit: AirBnB style guide