In this document
In order to improve the clarity, quality and development time it is worth considering the following principles whenever possible:
- DRY (Don't Repeat Yourself)
- KISS (Keep It Simple, Stupid)
- SoC (Separation of Concerns)
- Single responsibility principle
- Law of Demeter
-
Airbnb JavaScript Style Guide is being followed in our code base.
-
Code formatting is handled entirely by Prettier. Run
npm run prettifyfrom the root of the project to format all code. Code is also automatically formatted pre-commit.
- Use
localize('...')or<Localize i18n_default_text='...'for translations. - Do NOT use
variablestolocalize(), this will break the translations, for example:
// Do NOT use this
localize(item.title)
// Use this
localize('title')- Use
website_nameconstant instead ofDeriv. - Do NOT use
<Element attributeName={true} />; just use<Element attributeName />. - Always name your components before default exporting them, for example:
import React from 'react';
const Loading = ({theme}) => (
<div className={`barspinner ${ theme || 'dark'}`}>
{ Array.from(new Array(5)).map((x, inx) => (
<div key={inx} className={`rect${inx + 1}`}></div>
))}
</div>
);
export default Loading;- There are cases where you do not want your strings to be escaped (i.g. when you place
<a/>tags inside a<Table />). To bypass HTML escape, you can use theinterpolation.escapeValueboolean property of the localizeoptionsparam (under normal circumstances do NOT use this.):
localize('{{opening_tag}}Deriv App{{closing_tag}}', {
opening_tag : '<a href="https://app.deriv.com" rel="noopener noreferrer" target="_blank" class="link">',
closing_tag : '</a>',
interpolation: { escapeValue: false },
}),