React-Style-Guide

A Reactjs coding style guide

This project is maintained by LinuxDevil

Don’t ignore rejected promises

For the same reason you shouldn’t ignore caught errors from try/catch.

Bad:

getUser()
  .then((user: User) => {
    return sendEmail(user.email, 'Welcome!');
  })
  .catch((error) => {
    console.log(error);
  });

Good:

import { logger } from './logging';

getUser()
  .then((user: User) => {
    return sendEmail(user.email, 'Welcome!');
  })
  .catch((error) => {
    logger.log(error);
  });

// or using the async/await syntax:

try {
  const user = await getUser();
  await sendEmail(user.email, 'Welcome!');
} catch (error) {
  logger.log(error);
}

_## Formatting

Formatting is subjective. Like many rules herein, there is no hard and fast rule that you must follow. The main point is DO NOT ARGUE over formatting. There are tons of tools to automate this. Use one! It’s a waste of time and money for engineers to argue over formatting. The general rule to follow is keep consistent formatting rules.

Refer also to this great TypeScript StyleGuide and Coding Conventions source._