-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a new module for the performance. Updated previous modules
- Loading branch information
Showing
8 changed files
with
221 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# [React](https://github.com/rolling-scopes-school/tasks/tree/master/react) Performance 🌟 | ||
|
||
## Module Overview 📚 | ||
|
||
The "React Performance" module delves into techniques and best practices to optimize the performance of React applications. Students will gain insights into various strategies to enhance the speed and efficiency of their React projects. The module covers topics such as code splitting, lazy loading, memoization, and the use of performance monitoring tools to identify and address bottlenecks. | ||
|
||
## Learning Objectives 🎯 | ||
|
||
Students will: | ||
|
||
- Understand the importance of performance optimization in React applications. | ||
- Learn how to use React's **memoization** techniques to prevent unnecessary re-renders. | ||
- Know how to effectively use **React keys** to optimize list rendering. | ||
- Understand the use of **React's useCallback** hook to memoize callback functions. | ||
- Understand how to use **React.memo** to optimize functional components. | ||
- Learn how to use **React's Profiler** to identify performance bottlenecks. | ||
- Learn about **code splitting** and **lazy loading** to improve application load times. | ||
- Understand the impact of **reconciliation** and how to optimize it. | ||
- Learn about **virtualization** techniques to efficiently render large lists. | ||
- Know how to use performance monitoring tools to track and improve application performance. | ||
|
||
## Approximate Module Completion Time ⏱️ | ||
|
||
- **7 hours** | ||
|
||
## Theory 📖 | ||
|
||
Students are encouraged to explore the following resources: | ||
|
||
1. **useCallback, useMemo, React.memo** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# React Performance | ||
|
||
## Application Requirements | ||
|
||
1. Fetch and Display Data | ||
- Fetch country data from the [REST Countries API](https://restcountries.com/v3.1/all). | ||
- Display a list of countries, including their name, population, region, and flag. | ||
2. Add Filtering and Sorting | ||
- Filter: Allow users to filter countries by region using a dropdown menu. | ||
- Search: Add a search bar for users to search countries by name. | ||
- Sort: Include an option to sort countries by population or name (ascending/descending). | ||
3. Optimize the App for Performance | ||
- useMemo: Use useMemo to memoize the filtered, searched, and sorted list of countries. | ||
- useCallback: Use useCallback to memoize event handler functions for filtering, searching, and sorting. | ||
- React.memo: Wrap components like individual country cards in React.memo to prevent unnecessary re-renders. | ||
- key: Ensure proper use of key props for lists to avoid reconciliation issues. | ||
4. Highlight countries visited by the user (you can store visited countries in the local storage). | ||
|
||
## Technical Requirements | ||
|
||
1. Create a separate branch for this task. Branch name: "performance". For this task, you will need to create a new application. | ||
2. Follow the requirements for the project setup listed [here](./project-setup.md) | ||
|
||
## Points | ||
|
||
### Student can get 100 points: | ||
|
||
- Fetch and display country data, including name, population, region, and flag - **10 points** | ||
- Filtering by region using a dropdown menu - **10 points** | ||
- Searching countries by name using a search bar - **10 points** | ||
- Sorting countries by population or name (ascending/descending) - **10 points** | ||
- Optimization using useMemo, useCallback, React.memo, and proper use of key props - **50 points** | ||
- Highlighting countries visited by the user, stored in local storage - **10 points** | ||
|
||
### Penalties | ||
|
||
- Usage of component libraries, e.g., Material UI, Ant Design: **-100 points** | ||
- TypeScript isn't used: **-95 points** | ||
- Usage of _any_: **-20 points per each** | ||
- Usage of _ts-ignore_: **-20 points per each** | ||
- Presence of _code-smells_ (God-object, chunks of duplicate code), commented code sections: **-10 points per each** | ||
- Commits after the deadline: **-40 points** | ||
- Pull Request doesn't follow guideline (including checkboxes in Score) [PR example](https://docs.rs.school/#/en/pull-request-review-process?id=pull-request-description-must-contain-the-following): **-10 points** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# React Vite project setup with Eslint, Prettier and Husky | ||
|
||
## Technical requirements | ||
|
||
1. Language Requirement | ||
- Use **TypeScript** for the project. | ||
2. Project Setup | ||
|
||
- Initialize the project using [Vite](https://vitejs.dev/guide/) with the [_react-ts_ template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts). | ||
```sh | ||
# npm 7+, extra double-dash is needed: | ||
npm create vite@latest rs-react-app -- --template react-ts | ||
``` | ||
|
||
3. Code Quality Tools | ||
|
||
1. ESLint | ||
- ESlint v.9 is already a part of the _react-ts_ setup. | ||
2. Prettier | ||
|
||
- Integrate Prettier for code formatting. | ||
You can execute the following command to add missing plugins: | ||
|
||
```sh | ||
npm install -D eslint-plugin-react eslint-plugin-prettier eslint-config-prettier eslint-plugin-react-compiler@beta | ||
npm install -D --save-exact prettier | ||
``` | ||
|
||
Now, add a new file `.prettierrc` to the root of the project: | ||
|
||
```json | ||
{ | ||
"trailingComma": "es5", | ||
"tabWidth": 2, | ||
"semi": true, | ||
"singleQuote": true | ||
} | ||
``` | ||
|
||
And this is how your `eslint.config.js` should look like: | ||
|
||
```js | ||
import js from "@eslint/js"; | ||
import globals from "globals"; | ||
import reactHooks from "eslint-plugin-react-hooks"; | ||
import reactRefresh from "eslint-plugin-react-refresh"; | ||
import react from "eslint-plugin-react"; | ||
import tseslint from "typescript-eslint"; | ||
import eslintPluginPrettier from "eslint-plugin-prettier/recommended"; | ||
import reactCompiler from "eslint-plugin-react-compiler"; | ||
export default tseslint.config( | ||
{ ignores: ["dist"] }, | ||
{ | ||
extends: [ | ||
js.configs.recommended, | ||
...tseslint.configs.strict, | ||
eslintPluginPrettier, | ||
], | ||
files: ["**/*.{ts,tsx}"], | ||
languageOptions: { | ||
ecmaVersion: 2020, | ||
globals: globals.browser, | ||
}, | ||
plugins: { | ||
react, | ||
"react-hooks": reactHooks, | ||
"react-refresh": reactRefresh, | ||
"react-compiler": reactCompiler, | ||
}, | ||
rules: { | ||
...reactHooks.configs.recommended.rules, | ||
"react-refresh/only-export-components": [ | ||
"warn", | ||
{ allowConstantExport: true }, | ||
], | ||
"react-compiler/react-compiler": "error", | ||
...react.configs.recommended.rules, | ||
...react.configs["jsx-runtime"].rules, | ||
}, | ||
settings: { | ||
react: { | ||
version: "detect", | ||
}, | ||
}, | ||
}, | ||
); | ||
``` | ||
3. Husky | ||
- Add Husky and configure it to run `lint` command on pre-commit. | ||
```sh | ||
npm install --save-dev husky | ||
``` | ||
You can follow the official [Husky documentation](https://typicode.github.io/husky/get-started.html) | ||
4. package.json commands | ||
- Add the following npm scripts: | ||
- `format:fix`: For running Prettier's --write command. | ||
```json | ||
"format:fix": "prettier --write ." | ||
``` | ||
You can check the final setup [here](https://github.com/kravaring/rs-react-app). |
Oops, something went wrong.