- Core:
react,react-dom,react-router,redux,redux-toolkit,axios - Dev:
npm,react-scripts,react-css-modules,sass,prettier - UI:
material-ui
installAdd dependenciesuninstallRemove dependenciesupgradeUpgrade dependencies
devStarts app in development mode.buildCreates an optimized production build.serveServes/build.analyzeAnalyzes app's bundle size.formatFormats staged files.
Files with different types named this way: [fle_name].[type].[extension], e.g.
foo.test.js,foo.container.js,foo.reducer.js,foo.ac.js(action creators),foo.module.scss.
- Folders, css files, JS files and variables that are not component are camelCase.
- class names and Components are PascalCase.
Order of imports:
// node_modules
import React from 'react';
import React, { useState, useEffect, useRef } from 'react';
import { bindActionCreators } from 'redux';
import { useSelector, useDispatch } from 'react-redux';
// other: components, utils, actions, ...
import { fetchHumanResources } from 'redux/actions';
import Calendar from './calendar';
// assets
import { ReactComponent as Icon } from 'assets/icons/icon.svg';
// css
import './styles.scss';With help of babel-plugin for react-css-modules we can use stylesheets and classes in a better way.
import css from 'app.module.scss';
const App = () => {
return (
<>
<div className={css.container}></div>
<div className={css['some-thing']}></div>
</>
);
};Any variable that is not depend on component state or props should be outside of on it!
Following is the order of logics inside component:
- Expressions and Computations
- useRefs, useContexts and useDispatch
- Local State: useState and useReducer
- Global State: useSelector
- Side Effects: useEffect
- Functions and Handlers
- return (
<Element />)
const obj = {
title: 'foo'
}
const Component = (props) => {
const foo = props.foo;
const arr = props.array.map(el => el);
const x = func();
const y = useMemo(() => /* computations */, [])
const ref = useRef(null);
const { value } = useContext(context);
const dispatch = useDispatch();
const [state, state] = useState(false);
const [state2, dispatchLocal] = useReducer(reducer, initialState);
const { ... } = useSelector(selector);
useEffect(() => /* side effects */, []);
const clickHandler = e => {}
return (
<div onClick={clickHandler} foo={foo}>
Hello World!
</div>
)
}
export default Component;