>
KeepCoding Projects - Web 18: 📁 repos-kc-web-18.md
>
Choose Your Language: Spanish 🔄 German
To practice and demonstrate the knowledge acquired during virtual classes, this project consists of creating a Single Page Application (SPA) using React, which will serve as the graphical interface to manage the ads API through a backend called Nodepop.
- React: Declarative library for building user interfaces.
- Components: Reusable, independent, hierarchical.
React.createElement(type, props, children)
ReactDOM.render(element, container)
- JSX:
- HTML-like syntax.
- Attributes:
className
,htmlFor
, etc. - Spread attributes:
<Component {...props} />
- children: Inner content between tags.
- Props: Parameters received by a component (
props.name
) - Nested components
- React.Fragment: Groups without adding extra nodes.
- Conditional rendering:
if
,? :
,&&
- Lists: Using
.map()
and uniquekey
s - Events:
onClick
,onChange
, etc.
useState(initialValue)
to manage local state.- Lifting state up: Sharing state between components.
- Controlled inputs: Managed with
useState
- Uncontrolled inputs: Accessed using
useRef
- Checkboxes / Radio Buttons
- Form submission:
onSubmit
,event.preventDefault()
Using useEffect
, its anatomy (dependencies, cleanup), and its behavior in StrictMode
.
Custom hooks for reusable logic.
Creating contexts with React.createContext
, providing them with Context.Provider
, and consuming them using useContext
.
- useRef: Access DOM or persistent values between renders.
- forwardRef: Forward refs to child components.
- React.memo: Avoids unnecessary re-renders if props haven't changed.
- useCallback(fn, deps): Memoizes functions.
- useMemo(fn, deps): Memoizes expensive computed values.
Using React.lazy
and Suspense
for lazy loading of components and Code splitting
to reduce initial bundle size.
/login
—> LoginPage- Form with email, password, and “Remember session” checkbox. Saves token after successful login.
-
/
—> Redirects to/adverts
- List of ads showing name, price, buy/sell status, and tags.
- Includes filters (name, type, price, tags).
- Link to ad detail and create new ad.
- Displays message if there are no ads.
-
/adverts
,/adverts/:id
—> AdvertPage- Shows details with image or placeholder.
- Redirects to 404 if not found.
- Delete button with confirmation. Redirects to list after deletion.
-
/adverts/new
—> NewAdvertPage- Form with name, type, tags, price, and optional photo.
- React validations. Redirects to detail after creation.
-
Any other route —>
NotFoundPage (404)
Filters in AdvertsPage:
- At least two filters: name, buy/sell, price, or tags.
- Two ways to apply filters:
- Frontend filtering with all ads loaded.
- Backend filtering by sending query parameters (recommended).
Key Technical Features:
- Authentication with JWT token.
- Protected routes and automatic redirection to login.
- Session persistence using localStorage.
- Axios with token interceptor.
- Tailwind CSS for styling.
- React Router for navigation.
- Form validation using React.
- Languages: HTML, CSS, JavaScript, TypeScript.
- Key dependencies (Node.js): React, Vite, Tailwind CSS, TypeScript, ESLint, Axios, clsx, Globals, Prettier.
This project depends on the nodepop-api
REST API. To interact with the mock database, you must first start the server that runs the API.
- Node.js (tested on version v22.15.1)
- Git (tested on version 2.47.1.windows.1)
- Visual Studio Code (tested on version 1.99.0)
- nodepop-api (REST API) (created by instructor David Jiménez - KeepCoding)
git clone https://github.com/pablo-sch/keepcoding-08-react-fundamentals.git
>
VSCode Clone Demo: 🎥 Gif Demo
Once the API is running, create a new user using Swagger at http://localhost:3001/swagger/
to be able to log in.
# Installs project dependencies.
npm install
# Starts development server.
npm run dev
# Builds production-ready app.
npm run build
# Checks code for errors.
npm run lint
# Previews production build locally.
npm run preview
# Formats code automatically
npm run format
>
Nodepop-API Endpoints: 📄 Endpoints
>
Project Preview: 👀 Preview
Project under MIT license. Free use and distribution with attribution. External contributions not accepted, but suggestions welcome.