React Fruit List Application to exemplify some React framework features.
Implement a feature to allow item selection with the following requirements:
- Clicking an item selects/unselects it.
- Multiple items can be selected at a time.
- Make sure to avoid unnecessary re-renders of each list item in the big list (performance).
- Currently selected items should be visually highlighted.
- Currently selected items' names should be shown at the top of the page.
Feel free to change the component structure at will.
To allow multiple item selection, goal number 3 on the goals list above, at the time we use a selectedItems
array on the List
component to hold the selected items but we use a little trick. Instead of implementing a classic React useState
hook on the component to manipulate the selectedItems
list and trigger a component re-render on every item select or deselect action, we use a simple array constant and manipulate it without ever changing the variable reference. This "trick" leverages the possibility of using an array for collecting the selected values without triggering re-renders to the list component unnecessarily, thus avoiding heavy re-rendering operations since the list holds a vast number of children.
For style generation we follow the BEM
methodology, as suggested by the initial implementation.
The relevant files for this implementation are located inside the src/components
folder and src/tools/constants.ts
.
The code is commented in the relevant places for better understanding of each implementation goal.
React
framework (with Typescript) for the overall application development;Typescript
coding language;SASS
style pre-processor to build the needed application styles;DotEnv
to load project environment variables;Webpack
to bundle the application and serve it in development mode;PicniCSS
lightweight CSS framework for UI styling;
Prettier
for code formatting;Webpack
to bundle the application and serve it in development mode;Log4Brains
to manage Architectural Decision Record (ADR) and generate static HTML knowledge base;Statoscope
to generate reports about the application;
Jest
javascript testing framework;React Testing Library
testing framework for working with React components;
From the project root folder, please execute the following commands in a terminal window:
npm i
npm start