├── /build/ # compiled output
├── /docs/ # Documentation files
├── /node_modules/ # 3rd party lib
├── /public/ # Static files
├── /src/ # The source code of the application
├───── /components/ # React components
├──────├──────/admin # dashboard, admin
├──────├──────/common # shared components
├──────├──────/icons # icons
├──────├──────/news # news specific components
├──────├──────/static # static page
├────── redux/ # redux (Seperate into sub folders based on functions as well as complexity rises)
├──────├──────/actions # action types, action creators
├──────├──────/reducers # reducers
├──────├──────store.js # store.js
├────── /utils/ # server schema and data models
├────── /routes/ # Routes/Page files
├────── /clientScript.js # Client-side startup script
├────── /config.js # application settings
├────── ...
├── /test/ # Unit tests
├── package.json
└── yarn.lock
- Install the necessary dependencies.
npm install
- To start the development server, execute the following command.
npm start
- To start the cypress test, execute the following command.
npm test
- To start the production build, execute the following command.
npm run build
- Cypress
- Husky
- Lint Staged
- Prettier
- ESLint
- ESLint Airbnb Config
- ESLint Prettier Config
- ESLint Import Plugin
- ESLint JSX a11y Plugin
- ESLint Prettier Plugin
- ESLint React Plugin
We've implemented interceptors to automatically log the API requests and responses through axios in development environment. So, you need to import the custom axios instance instead of directly importing from the axios package.
import axios from "./utils/axiosInterceptor";In ./utils/axiosInterceptor.js, change the <Base_URL> to your backend server's base url. For example, http://127.0.0.1:5000 for flask.
Error boundaries are React components that catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI instead of the component tree that crashed.
import ErrorBoundary from "../components/common/ErrorBoundary"
const App = () => {
return (
<div>
<p>Hello, React!</p>
<ErrorBoundary>
<SomeComponent>
</ErrorBoundary>
</div>
)
}You may wrap top-level route components to display a “Something went wrong” message to the user or you may also wrap individual components in an error boundary to protect them from crashing the rest of the application.
React has some built-in type-checking abilities. To run type-checking on the props for a component, you can assign the special propTypes property.
import PropTypes from "prop-types";
class Greetings extends React.Component {
constructor(props) {
super(props);
}
render() {
const { name } = this.props;
return <h1>Hello, {name}</h1>;
}
}
Greeting.propTypes = {
name: PropTypes.string
};A typical redux setup should have the following files in their respective folder.
-
actionsTypes.js, to declare your different actions in redux. Like this. -
actions.js, to write your actions. Like this. -
reducer.js, to manage your reducer's state. Like this.
Once it's done, you've to import the reducer to store.js and use it in the combineReducers.
Note: Redux DevTools is already setup for development and production. You can download the extension for your browser.
Refer the detailed documentation.
Refer the detailed documentation.
Refer the detailed documentation.
Refer the detailed documentation
-
All the files having JSX should have an extension of
.jsx -
Always de-structure your state & props before using them. Refer to MDN for reference.
-
Use propTypes for all your props to ensure type-checking. Refer to React Docs for reference.
-
Async updates to redux must be handled through redux-thunk.
-
Individual components should be styled using
css modules. Refer to CRA Docs for reference. -
Always handle error in promises with
catchmethod.