⭐️Nested Routes and Index Route⭐️
with react-router-dom
Child Route like this:
The path: "/app/cities"
"/app" → Parent Route
"/citites" → Child Route
Nested Routes like this:
So, <AppLayout /> is the element that's rendered in "/app" any components are exist in <Applayout />
We can use
Then, The elements at Child Routes will rendered at any place in "/app" by instead of <Outlet />
⭐️index Route⭐️
like this:
index={true} is same path={"/"}
or same path of Parent Route
with react-router-dom
Child Route like this:
<Route path={"/app/cities"} element={<CityList />}/>
The path: "/app/cities"
"/app" → Parent Route
"/citites" → Child Route
Nested Routes like this:
<Route path={"/app"} element={<AppLayout/>}>
// Child Routes here
</Route>
So, <AppLayout /> is the element that's rendered in "/app" any components are exist in <Applayout />
We can use
<Outlet />
in any components in AppLayout<Outlet />
this to render elements that in Child Routes Then, The elements at Child Routes will rendered at any place in "/app" by instead of <Outlet />
⭐️index Route⭐️
like this:
<Route index={true} element={<Cities />}/>
index={true} is same path={"/"}
or same path of Parent Route
🥰2👍1
What happen when enter wrong Route in URL ??
- We will add new Route in globally, his path will be "*"
like this:
this Route will be the last Route inside <Routes> ... </Routes>
- We will add new Route in globally, his path will be "*"
like this:
<Route path={"*"} element={<PageNotFound/>}/>
this Route will be the last Route inside <Routes> ... </Routes>
🔥1🥰1
⭐️Storing state in the URL⭐️
URL is the best place to store UI state and alternative to useState
(example): open or close panels - currently selected list item - list sorting order - applied list filter
- This useful to make bookmark and share the page
URL like this:
/app/cities → Path
/lisbon → params
?lat=38.1242&lang=-9.8364 → query string
params → very useful to pass data to the next page
query string → useful to store some global state
I recommend this topic that about DNS:
https://maryam-eid.medium.com/decoding-the-web-iv-dns-domain-names-9e0c5b3a0f27
URL is the best place to store UI state and alternative to useState
(example): open or close panels - currently selected list item - list sorting order - applied list filter
- This useful to make bookmark and share the page
URL like this:
localhost:5173/app/cities/lisbon?lat=38.1242&lang=-9.8364
/app/cities → Path
/lisbon → params
?lat=38.1242&lang=-9.8364 → query string
params → very useful to pass data to the next page
query string → useful to store some global state
I recommend this topic that about DNS:
https://maryam-eid.medium.com/decoding-the-web-iv-dns-domain-names-9e0c5b3a0f27
❤1🔥1
⭐️So to use Params with React Router⭐️
Step-1: Create a new Route
Step-2: Link to that Route (useParam)
Step-3: In that Route, we read the state from URL
1-
Route example:
here "83723" is "id" param
and "madrid" is "cityname" param
2-
here must use template literals with params
3-
Then to get that data from URL.
We use
We will use this hook only at component in the Route have param like this in step-1 in <City /> component.
to install React Router (¬‿¬)
Step-1: Create a new Route
Step-2: Link to that Route (useParam)
Step-3: In that Route, we read the state from URL
1-
<Route path={"/app/cities/:id/:cityname"} element={<City/>}/>
Route example:
localhost:5173/app/cities/83723/madrid
here "83723" is "id" param
and "madrid" is "cityname" param
2-
<Link to={`/app/cities/${ele.id}/${ele.cityName}`}> ...... </Link>
here must use template literals with params
3-
Then to get that data from URL.
We use
useParams()
hook.We will use this hook only at component in the Route have param like this in step-1 in <City /> component.
import {useParams} from "react-router-dom";
const {id, cityname} = useParams();
useParams()
provided by React Routerto install React Router (¬‿¬)
npm install react-router-dom@version
❤3
⭐️In Express.js⭐️
XSS-attack in Back-end.
This the best way to solve.
You can use
to install xss library:
example:
XSS-attack in Back-end.
This the best way to solve.
You can use
xss library
and this middleware instead.to install xss library:
npm install xss
// 1. turning object into a big string using JSON.stringify
// 2. sanitize it using xss
// 3. parsing it after sanitization
app.use((req, res, next) => {
const sanitizeBody = xss(JSON.stringify(req.body));
req.body = JSON.parse(sanitizeBody);
// 🫡dont forget to add req.params req.query and ....
next();
});
example:
// input:⚠️
{
test: [
{
t: "this is my .md content. <strong>yo<strong> <script>alert('xss');</script> ",
a: "<script>alert('xss');</script>",
ts: "<script>alert('xss');</script>",
testing: [Array]
}
]
}
// result:🧼
{
t: "this is my .md content. <strong>yo<strong> <script>alert('xss');</script> ",
a: "<script>alert('xss');</script>",
ts: "<script>alert('xss');</script>",
testing: [ { now: "<script>alert('xss');</script>" } ]
}
👎1🔥1🥰1
React.js Notes
⭐️ESlint configuration at React with vite⭐️ When initialize React app with vite npm create vite@latest don't forget configure Eslint npm install eslint vite-plugin-eslint eslint-config-react-app --save-dev And create new file at globally .eslintrc.json…
Update🔥
In React with Vite
Don't install
Just install
This is because
So that, Only install this
In React with Vite
Don't install
eslint-config-react-app
Just install
eslint and vite-plugin-eslint
This is because
eslint-config-react-app
is specific to create-react-app
eslint-config-react-app
No longer for last version for vite.So that, Only install this
npm install eslint vite-plugin-eslint --save-dev
🔥3
⭐️React Native 0.76 with New Architecture⭐️
The New Architecture adds full support for modern React features, including Suspense, Transitions, automatic batching, and useLayoutEffect. The New Architecture also includes new Native Module and Native Component systems that let you write type-safe code with direct access to native interfaces without a bridge.
The New Architecture includes four main parts:
🔹 Synchronous Native Modules:
Type-safe access to native code without the bridge, written in C++ for speed and cross-platform compatibility.
🔹 New Renderer:
Multiple threads allow updates at various priorities, improving responsiveness and reducing jank.
🔹 Event Loop:
Prioritizes urgent updates, aligns with web standards, and lays the groundwork for browser features like microtasks and
🔹 Bridge Removed:
Faster startup and enhanced performance by enabling direct JavaScript-native communication.
To see more details, Visit this site:
Full Blog Post
For detailed explanation:
Youtube Video
The New Architecture adds full support for modern React features, including Suspense, Transitions, automatic batching, and useLayoutEffect. The New Architecture also includes new Native Module and Native Component systems that let you write type-safe code with direct access to native interfaces without a bridge.
The New Architecture includes four main parts:
🔹 Synchronous Native Modules:
Type-safe access to native code without the bridge, written in C++ for speed and cross-platform compatibility.
🔹 New Renderer:
Multiple threads allow updates at various priorities, improving responsiveness and reducing jank.
🔹 Event Loop:
Prioritizes urgent updates, aligns with web standards, and lays the groundwork for browser features like microtasks and
IntersectionObserver
.🔹 Bridge Removed:
Faster startup and enhanced performance by enabling direct JavaScript-native communication.
To see more details, Visit this site:
Full Blog Post
For detailed explanation:
Youtube Video
👍1🔥1🥰1
⭐️Exploring the Power of the Reflect Object in JavaScript and Its Role in Nest.js Decorators⭐️
- The
- Nest.js leverages the reflect-metadata library, which works in tandem with the Reflect object to manage and retrieve this metadata.
🔗 Read the full article on Medium: Exploring the Reflect Object in JavaScript & Nest.js Decorators
I appreciate your time and curiosity. Enjoy reading! 💻📚
- The
Reflect
object in JavaScript is a versatile built-in object that allows developers to perform meta-programming tasks and interact with object properties and methods in a standardized way. It's particularly useful in frameworks like Nest.js, where it plays a critical role in enabling decorators.- Nest.js leverages the reflect-metadata library, which works in tandem with the Reflect object to manage and retrieve this metadata.
🔗 Read the full article on Medium: Exploring the Reflect Object in JavaScript & Nest.js Decorators
I appreciate your time and curiosity. Enjoy reading! 💻📚
👍1🥰1👌1
⭐️Make your ideas look awesome, without relying on a designer.⭐️
- Learn how to design beautiful user interfaces by yourself using specific tactics explained from a developer's point-of-view.
📂The entire book is free and attached in the following message.
refactoringui.com
#React #WebDevelopment #Coding #Book #UI #FrontEnd
- Learn how to design beautiful user interfaces by yourself using specific tactics explained from a developer's point-of-view.
📂The entire book is free and attached in the following message.
refactoringui.com
#React #WebDevelopment #Coding #Book #UI #FrontEnd
❤2
⭐️Learning Patterns by Lydia Hallie and Addy Osmani⭐️
- A must-read for React developers.
It explores best practices, design patterns, and key strategies for building efficient and scalable React applications.
- This book provides clear, actionable insights to enhance your coding skills and elevate your understanding of React's powerful ecosystem.
Perfect for both beginners and seasoned developers looking to optimize their workflow.
📂The entire book is free and attached in the following message.
#React #WebDevelopment #Coding #Book #UI #FrontEnd
- A must-read for React developers.
It explores best practices, design patterns, and key strategies for building efficient and scalable React applications.
- This book provides clear, actionable insights to enhance your coding skills and elevate your understanding of React's powerful ecosystem.
Perfect for both beginners and seasoned developers looking to optimize their workflow.
📂The entire book is free and attached in the following message.
#React #WebDevelopment #Coding #Book #UI #FrontEnd
❤1🥰1
Instead of using libs for envs, you can use this simple type-safe variant and forget about envs validation.
The post from this tweet Click here🔗
The post from this tweet Click here🔗
🥰1🏆1
🎉 react-emoji-toggle-button is available now!
A lightweight and customizable emoji picker built for modern React applications.
✨ Key Features:
✅ Light & Dark Themes
✅ English & Arabic UI Support
✅ Recent & Flag Emojis
✅ Filter Bad Emojis
✅ Fully Customizable Styles & Sizes
✅ Easy Integration with any input field
Perfect for chat apps, comment sections, and any interactive UI that deserves an expressive touch! 💬💛
🌐 Live Demo:
https://mahmoud-walid.github.io/react-emoji-toggle-button/
📦 Install via npm:
🔗 GitHub:
https://github.com/Mahmoud-walid/react-emoji-toggle-button
If you like it, don’t forget to ⭐️ the repo and share it with fellow developers! 🙌
Bring emojis to life in your app today! 🧑💻🚀
A lightweight and customizable emoji picker built for modern React applications.
✨ Key Features:
✅ Light & Dark Themes
✅ English & Arabic UI Support
✅ Recent & Flag Emojis
✅ Filter Bad Emojis
✅ Fully Customizable Styles & Sizes
✅ Easy Integration with any input field
Perfect for chat apps, comment sections, and any interactive UI that deserves an expressive touch! 💬💛
🌐 Live Demo:
https://mahmoud-walid.github.io/react-emoji-toggle-button/
📦 Install via npm:
npm i react-emoji-toggle-button
🔗 GitHub:
https://github.com/Mahmoud-walid/react-emoji-toggle-button
If you like it, don’t forget to ⭐️ the repo and share it with fellow developers! 🙌
Bring emojis to life in your app today! 🧑💻🚀
❤3🥰1🎉1