Skip to content

Instantly share code, notes, and snippets.

View alexzherdev's full-sized avatar

Alex Zherdev alexzherdev

View GitHub Profile
@alexzherdev
alexzherdev / state2.js
Created March 25, 2019 23:18
State initialization 2
class MyComponent extends React.Component {
constructor(props) {
super(props);
if (props.foo) { /*
* Now the assignment to this.state has a different parent.
* If you didn't expect to see an if condition here,
* the rule may crash.
*/
this.state = { /* some state */ };
} else {
@alexzherdev
alexzherdev / state.js
Created March 25, 2019 23:10
State initialization
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.state = { /* some state */ }; // <-- state initialization
}
}
@alexzherdev
alexzherdev / express-classes.js
Created March 13, 2019 05:35
Express routes - classes
class BaseHandler {
constructor() {
this.handler = this._handler.bind(this);
}
_handler(req, res, next) {
let result;
try {
result = this._execute.apply(this, [req, res, next]);
} catch (e) {
@alexzherdev
alexzherdev / express-fns.js
Created March 13, 2019 05:29
Express routes - functions
function createBaseHandler(handler) {
return function BaseHandler(req, res, next) {
let result;
try {
result = handler(req, res, next);
} catch (e) {
res.status(500);
res.end();
return;
}
function Component(props) {
return (
<button
onClick={() => {
console.log('inline functions bad'); // JSX props should not use arrow functions (react/jsx-no-bind)
}}
type="button"
/>
);
}