then chains are terrible. They quickly introduce nesting and become hard to read, refactor and work with.
Unless it really makes sense, never use them. Stick to async/await syntax.
Often it's worth creating an error boundary, especially for the new features or code that is highly likely to crash due to some data missing on the backend.
You can read more about them here.
Go through the React Recipes for testing and follow them when creating tests.
Do not create React Class Components, there is simply no use case that hooks can't cover. Embrace them fully. Here is the reference.
Keep the code DRY 🐪 (don't repeat yourself).
Keep It Simple Stupid! Write short functions, small components, simple logic. Don't complicate things.
We use material-ui library for UI components. Create reusable components like Button that are wrappers for the Button from the library but changed to match the Databook design.
Check out the example. We have a feature dir that contains a bunch of files. It’s easier to import it from index.js file because we can use one import statement to import multiple files.
You can use for simple helper functions instead of lodash. Never use lodash without tree shaking.
We are not using TypeScript for most projects, therefore having good prop types is crucial. Never use PropTypes.object or PropTypes.array. Define what is the shape of the object or what the type of items inside the array.
Read through the docs of material UI and try to follow them. Also, always use this format when defining styles for a component:
const useStyles = makeStyles(theme => ({
... your styles...
... this can also be an object, not a function, if you are not using theme
}));
// later in your component
const classes = useStyles();
Stick to the useStyles and classes naming.
When defining styles with pixels, such as below, notice there's no need to write 20px, you can simply use the number.
const useStyles = makeStyles(theme => ({
container: {
fontSize: 14,
padding: 20
},
}));
Remember - this is only valid for React style prop or useStyles! When preparing a objects with configurations for libraries such as Highcharts, you need to write proper styles as it doesn't use React internally.