SlideShare a Scribd company logo
1 of 78
Download to read offline
I'mPaulina🙋🏼‍♀️
I'mPaulina🙋🏼‍♀️
TeamLeadatOdrabiamy.pl
Ever
done
codereview?
Ever
received
codereview?
Ever
received
codereview?
🤕
Why
Why
Wearedevelopers!
Why
Wearedevelopers!
Focus
Wearedevelopers!
Focus
Softskills
Wearedevelopers!
Focus
Softskills
Unrewarding?
Andyetwedoit...
📝
Show the banner only if user
hasn't seen it yet
import { useCookies, CookiesProvider } from "react-cookie";
import Banner from "./Banner";
export default function WelcomePage() {
const [cookies, setCookie] = useCookies(["banner-seen"]);
const handleBannerClose = () => {
setCookie("banner-seen", true);
};
return (
<CookiesProvider>
<main>
{!cookies["banner-seen"] && <Banner onClose={handleBannerClose} />}
<div>Welcome to Alicante!</div>
</main>
</CookiesProvider>
);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { useCookies, CookiesProvider } from "react-cookie";
import Banner from "./Banner";
export default function WelcomePage() {
const [cookies, setCookie] = useCookies(["banner-seen"]);
const handleBannerClose = () => {
setCookie("banner-seen", true);
};
return (
<CookiesProvider>
<main>
{!cookies["banner-seen"] && <Banner onClose={handleBannerClose} />}
<div>Welcome to Alicante!</div>
</main>
</CookiesProvider>
);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { useCookies, CookiesProvider } from "react-cookie";
<CookiesProvider>
</CookiesProvider>
1
import Banner from "./Banner";
2
3
export default function WelcomePage() {
4
const [cookies, setCookie] = useCookies(["banner-seen"]);
5
6
const handleBannerClose = () => {
7
setCookie("banner-seen", true);
8
};
9
10
return (
11
12
<main>
13
{!cookies["banner-seen"] && <Banner onClose={handleBannerClose} />}
14
<div>Welcome to Alicante!</div>
15
</main>
16
17
);
18
}
19
import { useCookies, CookiesProvider } from "react-cookie";
import Banner from "./Banner";
export default function WelcomePage() {
const [cookies, setCookie] = useCookies(["banner-seen"]);
const handleBannerClose = () => {
setCookie("banner-seen", true);
};
return (
<CookiesProvider>
<main>
{!cookies["banner-seen"] && <Banner onClose={handleBannerClose} />}
<div>Welcome to Alicante!</div>
</main>
</CookiesProvider>
);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { useCookies, CookiesProvider } from "react-cookie";
<CookiesProvider>
</CookiesProvider>
1
import Banner from "./Banner";
2
3
export default function WelcomePage() {
4
const [cookies, setCookie] = useCookies(["banner-seen"]);
5
6
const handleBannerClose = () => {
7
setCookie("banner-seen", true);
8
};
9
10
return (
11
12
<main>
13
{!cookies["banner-seen"] && <Banner onClose={handleBannerClose} />}
14
<div>Welcome to Alicante!</div>
15
</main>
16
17
);
18
}
19
{!cookies["banner-seen"] && <Banner onClose={handleBannerClose} />}
import { useCookies, CookiesProvider } from "react-cookie";
1
import Banner from "./Banner";
2
3
export default function WelcomePage() {
4
const [cookies, setCookie] = useCookies(["banner-seen"]);
5
6
const handleBannerClose = () => {
7
setCookie("banner-seen", true);
8
};
9
10
return (
11
<CookiesProvider>
12
<main>
13
14
<div>Welcome to Alicante!</div>
15
</main>
16
</CookiesProvider>
17
);
18
}
19
import { useCookies, CookiesProvider } from "react-cookie";
import Banner from "./Banner";
export default function WelcomePage() {
const [cookies, setCookie] = useCookies(["banner-seen"]);
const handleBannerClose = () => {
setCookie("banner-seen", true);
};
return (
<CookiesProvider>
<main>
{!cookies["banner-seen"] && <Banner onClose={handleBannerClose} />}
<div>Welcome to Alicante!</div>
</main>
</CookiesProvider>
);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { useCookies, CookiesProvider } from "react-cookie";
<CookiesProvider>
</CookiesProvider>
1
import Banner from "./Banner";
2
3
export default function WelcomePage() {
4
const [cookies, setCookie] = useCookies(["banner-seen"]);
5
6
const handleBannerClose = () => {
7
setCookie("banner-seen", true);
8
};
9
10
return (
11
12
<main>
13
{!cookies["banner-seen"] && <Banner onClose={handleBannerClose} />}
14
<div>Welcome to Alicante!</div>
15
</main>
16
17
);
18
}
19
{!cookies["banner-seen"] && <Banner onClose={handleBannerClose} />}
import { useCookies, CookiesProvider } from "react-cookie";
1
import Banner from "./Banner";
2
3
export default function WelcomePage() {
4
const [cookies, setCookie] = useCookies(["banner-seen"]);
5
6
const handleBannerClose = () => {
7
setCookie("banner-seen", true);
8
};
9
10
return (
11
<CookiesProvider>
12
<main>
13
14
<div>Welcome to Alicante!</div>
15
</main>
16
</CookiesProvider>
17
);
18
}
19
const handleBannerClose = () => {
setCookie("banner-seen", true);
};
import { useCookies, CookiesProvider } from "react-cookie";
1
import Banner from "./Banner";
2
3
export default function WelcomePage() {
4
const [cookies, setCookie] = useCookies(["banner-seen"]);
5
6
7
8
9
10
return (
11
<CookiesProvider>
12
<main>
13
{!cookies["banner-seen"] && <Banner onClose={handleBannerClose} />}
14
<div>Welcome to Alicante!</div>
15
</main>
16
</CookiesProvider>
17
);
18
}
19
It would be better to use storage instead of
cookies. You don't need the info on the server.
Use camelCase for the cookie
naming, ok?
Are you serious with
keeping this in the
cookies?!
Do you even imagine the
impact the context has
on the app? 🤦
import { useState } from "react";
import Banner from "./Banner";
export default function WelcomePage() {
const [bannerSeen, setBannerSeen] = useState(
JSON.parse(localStorage.getItem("bannerSeen") ?? "false")
);
const handleBannerClose = () => {
setBannerSeen(true);
localStorage.setItem("bannerSeen", "true");
};
return (
<main>
{!bannerSeen && <Banner onClose={handleBannerClose} />}
<div>Welcome to Alicante!</div>
</main>
);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { useState } from "react";
import Banner from "./Banner";
export default function WelcomePage() {
const [bannerSeen, setBannerSeen] = useState(
JSON.parse(localStorage.getItem("bannerSeen") ?? "false")
);
const handleBannerClose = () => {
setBannerSeen(true);
localStorage.setItem("bannerSeen", "true");
};
return (
<main>
{!bannerSeen && <Banner onClose={handleBannerClose} />}
<div>Welcome to Alicante!</div>
</main>
);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
const [bannerSeen, setBannerSeen] = useState(
JSON.parse(localStorage.getItem("bannerSeen") ?? "false")
);
const handleBannerClose = () => {
setBannerSeen(true);
localStorage.setItem("bannerSeen", "true");
};
import { useState } from "react";
1
import Banner from "./Banner";
2
3
export default function WelcomePage() {
4
5
6
7
8
9
10
11
12
13
return (
14
<main>
15
{!bannerSeen && <Banner onClose={handleBannerClose} />}
16
<div>Welcome to Alicante!</div>
17
</main>
18
);
19
}
20
You probably don't know about more advanced concepts
like the new React hook that you could use -
useSyncExternalStore.
import { useSyncExternalStore } from "react";
import Banner from "./Banner";
const subscribeToLocalStorage = (callback: () => void) => {
window.addEventListener("storage", callback);
return () => {
window.removeEventListener("storage", callback);
};
};
const getLocalStorageSnapshot = () => localStorage.getItem("bannerSeen");
export default function WelcomePage() {
const bannerSeen = useSyncExternalStore(
subscribeToLocalStorage,
getLocalStorageSnapshot
);
const handleBannerClose = () => {
localStorage.setItem("bannerSeen", "true");
};
return (
<main>
{bannerSeen !== "true" && <Banner onClose={handleBannerClose} />}
<div>Welcome to Alicante!</div>
</main>
);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { useSyncExternalStore } from "react";
import Banner from "./Banner";
const subscribeToLocalStorage = (callback: () => void) => {
window.addEventListener("storage", callback);
return () => {
window.removeEventListener("storage", callback);
};
};
const getLocalStorageSnapshot = () => localStorage.getItem("bannerSeen");
export default function WelcomePage() {
const bannerSeen = useSyncExternalStore(
subscribeToLocalStorage,
getLocalStorageSnapshot
);
const handleBannerClose = () => {
localStorage.setItem("bannerSeen", "true");
};
return (
<main>
{bannerSeen !== "true" && <Banner onClose={handleBannerClose} />}
<div>Welcome to Alicante!</div>
</main>
);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const bannerSeen = useSyncExternalStore(
subscribeToLocalStorage,
getLocalStorageSnapshot
);
import { useSyncExternalStore } from "react";
1
import Banner from "./Banner";
2
3
const subscribeToLocalStorage = (callback: () => void) => {
4
window.addEventListener("storage", callback);
5
return () => {
6
window.removeEventListener("storage", callback);
7
};
8
};
9
10
const getLocalStorageSnapshot = () => localStorage.getItem("bannerSeen");
11
12
export default function WelcomePage() {
13
14
15
16
17
18
const handleBannerClose = () => {
19
localStorage.setItem("bannerSeen", "true");
20
};
21
22
return (
23
<main>
24
{bannerSeen !== "true" && <Banner onClose={handleBannerClose} />}
25
<div>Welcome to Alicante!</div>
26
</main>
27
);
28
}
29
The hook is especially useful when you want to subscribe
to some external store changes.
Also, storage event does not fire when changes to the storage
are made on the same page, so you would still need state.
Wow! I thought React 18 was like Nessie - everyone talks
about it, but no one has seen it!
Dan would be proud of you!
Just remember to still update state when user
closes the banner.
Motivation
Motivation
Negative
Motivation
Negative Neutral
Motivation
Negative Neutral Positive
Negative Neutral Positive
Negative Neutral Positive
Codeprotection
Revenge
Showingoff
Negative Neutral Positive
Codeprotection
Revenge
Showingoff
Duty
Negative Neutral Positive
Codeprotection
Revenge
Showingoff
Duty Knowledge
sharing
Personalgrowth
Empathy
Fun
Whichteamdoyouchoose?
Memes
Memes
Jokes
Memes
Jokes
Senseofhumour
Memes
Jokes
Senseofhumour
Propercodereview
Propercodereview
Doesitdothework?
Doesitdothework?
Withoutbreakinganything...
Doyoulikeit?
It'sworthit!
Thank you!
react-alicante-2023-paulina-chojnowska.pdf

More Related Content

Similar to react-alicante-2023-paulina-chojnowska.pdf

Vue JS @ MindDoc. The progressive road to online therapy
Vue JS @ MindDoc. The progressive road to online therapyVue JS @ MindDoc. The progressive road to online therapy
Vue JS @ MindDoc. The progressive road to online therapyDarío Blanco Iturriaga
 
Beginner’s tutorial (part 2) how to integrate redux-saga in react native app
Beginner’s tutorial (part 2) how to integrate redux-saga in react native appBeginner’s tutorial (part 2) how to integrate redux-saga in react native app
Beginner’s tutorial (part 2) how to integrate redux-saga in react native appKaty Slemon
 
PWA night vol.11 20191218
PWA night vol.11 20191218PWA night vol.11 20191218
PWA night vol.11 20191218bitpart
 
Leaving Interface Builder Behind
Leaving Interface Builder BehindLeaving Interface Builder Behind
Leaving Interface Builder BehindJohn Wilker
 
Modern Web Developement
Modern Web DevelopementModern Web Developement
Modern Web Developementpeychevi
 
Introductionandgreetings
IntroductionandgreetingsIntroductionandgreetings
IntroductionandgreetingsPozz ZaRat
 
Battle of React State Managers in frontend applications
Battle of React State Managers in frontend applicationsBattle of React State Managers in frontend applications
Battle of React State Managers in frontend applicationsEvangelia Mitsopoulou
 
UI 모듈화로 워라밸 지키기
UI 모듈화로 워라밸 지키기UI 모듈화로 워라밸 지키기
UI 모듈화로 워라밸 지키기NAVER SHOPPING
 
Animating angular applications
Animating angular applicationsAnimating angular applications
Animating angular applicationsTomek Sułkowski
 
import React, { useEffect } from react;import { BrowserRouter as.pdf
import React, { useEffect } from react;import { BrowserRouter as.pdfimport React, { useEffect } from react;import { BrowserRouter as.pdf
import React, { useEffect } from react;import { BrowserRouter as.pdfarkmuzikllc
 
Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Elyse Kolker Gordon
 
Recoil at Codete Webinars #3
Recoil at Codete Webinars #3Recoil at Codete Webinars #3
Recoil at Codete Webinars #3Mateusz Bryła
 
import React, { useEffect } from react;import { BrowserRouter as.pdf
import React, { useEffect } from react;import { BrowserRouter as.pdfimport React, { useEffect } from react;import { BrowserRouter as.pdf
import React, { useEffect } from react;import { BrowserRouter as.pdfstopgolook
 
Building a js widget
Building a js widgetBuilding a js widget
Building a js widgetTudor Barbu
 
Fórum de Software Livre do Serpro RJ 2009
Fórum de Software Livre do Serpro RJ 2009Fórum de Software Livre do Serpro RJ 2009
Fórum de Software Livre do Serpro RJ 2009Fabio Akita
 
Checkout Customizations in Magento 2 - MageTitansMCR 2017
Checkout Customizations in Magento 2 - MageTitansMCR 2017Checkout Customizations in Magento 2 - MageTitansMCR 2017
Checkout Customizations in Magento 2 - MageTitansMCR 2017Max Pronko
 

Similar to react-alicante-2023-paulina-chojnowska.pdf (20)

Vue business first
Vue business firstVue business first
Vue business first
 
Vue JS @ MindDoc. The progressive road to online therapy
Vue JS @ MindDoc. The progressive road to online therapyVue JS @ MindDoc. The progressive road to online therapy
Vue JS @ MindDoc. The progressive road to online therapy
 
Beginner’s tutorial (part 2) how to integrate redux-saga in react native app
Beginner’s tutorial (part 2) how to integrate redux-saga in react native appBeginner’s tutorial (part 2) how to integrate redux-saga in react native app
Beginner’s tutorial (part 2) how to integrate redux-saga in react native app
 
PWA night vol.11 20191218
PWA night vol.11 20191218PWA night vol.11 20191218
PWA night vol.11 20191218
 
Leaving Interface Builder Behind
Leaving Interface Builder BehindLeaving Interface Builder Behind
Leaving Interface Builder Behind
 
Modern Web Developement
Modern Web DevelopementModern Web Developement
Modern Web Developement
 
Introductionandgreetings
IntroductionandgreetingsIntroductionandgreetings
Introductionandgreetings
 
Battle of React State Managers in frontend applications
Battle of React State Managers in frontend applicationsBattle of React State Managers in frontend applications
Battle of React State Managers in frontend applications
 
UI 모듈화로 워라밸 지키기
UI 모듈화로 워라밸 지키기UI 모듈화로 워라밸 지키기
UI 모듈화로 워라밸 지키기
 
Animating angular applications
Animating angular applicationsAnimating angular applications
Animating angular applications
 
FP512 Cookies sessions
FP512 Cookies sessionsFP512 Cookies sessions
FP512 Cookies sessions
 
import React, { useEffect } from react;import { BrowserRouter as.pdf
import React, { useEffect } from react;import { BrowserRouter as.pdfimport React, { useEffect } from react;import { BrowserRouter as.pdf
import React, { useEffect } from react;import { BrowserRouter as.pdf
 
Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017Building Universal Web Apps with React ForwardJS 2017
Building Universal Web Apps with React ForwardJS 2017
 
Side effects-con-redux
Side effects-con-reduxSide effects-con-redux
Side effects-con-redux
 
Recoil at Codete Webinars #3
Recoil at Codete Webinars #3Recoil at Codete Webinars #3
Recoil at Codete Webinars #3
 
import React, { useEffect } from react;import { BrowserRouter as.pdf
import React, { useEffect } from react;import { BrowserRouter as.pdfimport React, { useEffect } from react;import { BrowserRouter as.pdf
import React, { useEffect } from react;import { BrowserRouter as.pdf
 
Building a js widget
Building a js widgetBuilding a js widget
Building a js widget
 
Fórum de Software Livre do Serpro RJ 2009
Fórum de Software Livre do Serpro RJ 2009Fórum de Software Livre do Serpro RJ 2009
Fórum de Software Livre do Serpro RJ 2009
 
React native by example by Vadim Ruban
React native by example by Vadim RubanReact native by example by Vadim Ruban
React native by example by Vadim Ruban
 
Checkout Customizations in Magento 2 - MageTitansMCR 2017
Checkout Customizations in Magento 2 - MageTitansMCR 2017Checkout Customizations in Magento 2 - MageTitansMCR 2017
Checkout Customizations in Magento 2 - MageTitansMCR 2017
 

Recently uploaded

ALCOHOL PRODUCTION- Beer Brewing Process.pdf
ALCOHOL PRODUCTION- Beer Brewing Process.pdfALCOHOL PRODUCTION- Beer Brewing Process.pdf
ALCOHOL PRODUCTION- Beer Brewing Process.pdfMadan Karki
 
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisSeismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisDr.Costas Sachpazis
 
Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...IJECEIAES
 
Diploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfDiploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfJNTUA
 
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxSLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxCHAIRMAN M
 
AI in Healthcare Innovative use cases and applications.pdf
AI in Healthcare Innovative use cases and applications.pdfAI in Healthcare Innovative use cases and applications.pdf
AI in Healthcare Innovative use cases and applications.pdfmahaffeycheryld
 
The Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptxThe Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptxMANASINANDKISHORDEOR
 
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfInvolute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfJNTUA
 
"United Nations Park" Site Visit Report.
"United Nations Park" Site  Visit Report."United Nations Park" Site  Visit Report.
"United Nations Park" Site Visit Report.MdManikurRahman
 
21scheme vtu syllabus of visveraya technological university
21scheme vtu syllabus of visveraya technological university21scheme vtu syllabus of visveraya technological university
21scheme vtu syllabus of visveraya technological universityMohd Saifudeen
 
Dynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxDynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxMustafa Ahmed
 
Geometric constructions Engineering Drawing.pdf
Geometric constructions Engineering Drawing.pdfGeometric constructions Engineering Drawing.pdf
Geometric constructions Engineering Drawing.pdfJNTUA
 
Artificial Intelligence in due diligence
Artificial Intelligence in due diligenceArtificial Intelligence in due diligence
Artificial Intelligence in due diligencemahaffeycheryld
 
Operating System chapter 9 (Virtual Memory)
Operating System chapter 9 (Virtual Memory)Operating System chapter 9 (Virtual Memory)
Operating System chapter 9 (Virtual Memory)NareenAsad
 
Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1T.D. Shashikala
 
Piping and instrumentation diagram p.pdf
Piping and instrumentation diagram p.pdfPiping and instrumentation diagram p.pdf
Piping and instrumentation diagram p.pdfAshrafRagab14
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...josephjonse
 
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...Amil baba
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxMustafa Ahmed
 
analog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxanalog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxKarpagam Institute of Teechnology
 

Recently uploaded (20)

ALCOHOL PRODUCTION- Beer Brewing Process.pdf
ALCOHOL PRODUCTION- Beer Brewing Process.pdfALCOHOL PRODUCTION- Beer Brewing Process.pdf
ALCOHOL PRODUCTION- Beer Brewing Process.pdf
 
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisSeismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
 
Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...
 
Diploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfDiploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdf
 
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptxSLIDESHARE PPT-DECISION MAKING METHODS.pptx
SLIDESHARE PPT-DECISION MAKING METHODS.pptx
 
AI in Healthcare Innovative use cases and applications.pdf
AI in Healthcare Innovative use cases and applications.pdfAI in Healthcare Innovative use cases and applications.pdf
AI in Healthcare Innovative use cases and applications.pdf
 
The Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptxThe Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptx
 
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfInvolute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
 
"United Nations Park" Site Visit Report.
"United Nations Park" Site  Visit Report."United Nations Park" Site  Visit Report.
"United Nations Park" Site Visit Report.
 
21scheme vtu syllabus of visveraya technological university
21scheme vtu syllabus of visveraya technological university21scheme vtu syllabus of visveraya technological university
21scheme vtu syllabus of visveraya technological university
 
Dynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxDynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptx
 
Geometric constructions Engineering Drawing.pdf
Geometric constructions Engineering Drawing.pdfGeometric constructions Engineering Drawing.pdf
Geometric constructions Engineering Drawing.pdf
 
Artificial Intelligence in due diligence
Artificial Intelligence in due diligenceArtificial Intelligence in due diligence
Artificial Intelligence in due diligence
 
Operating System chapter 9 (Virtual Memory)
Operating System chapter 9 (Virtual Memory)Operating System chapter 9 (Virtual Memory)
Operating System chapter 9 (Virtual Memory)
 
Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1Research Methodolgy & Intellectual Property Rights Series 1
Research Methodolgy & Intellectual Property Rights Series 1
 
Piping and instrumentation diagram p.pdf
Piping and instrumentation diagram p.pdfPiping and instrumentation diagram p.pdf
Piping and instrumentation diagram p.pdf
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
 
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptx
 
analog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxanalog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptx
 

react-alicante-2023-paulina-chojnowska.pdf

  • 1.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24. Why
  • 30. 📝 Show the banner only if user hasn't seen it yet
  • 31. import { useCookies, CookiesProvider } from "react-cookie"; import Banner from "./Banner"; export default function WelcomePage() { const [cookies, setCookie] = useCookies(["banner-seen"]); const handleBannerClose = () => { setCookie("banner-seen", true); }; return ( <CookiesProvider> <main> {!cookies["banner-seen"] && <Banner onClose={handleBannerClose} />} <div>Welcome to Alicante!</div> </main> </CookiesProvider> ); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
  • 32. import { useCookies, CookiesProvider } from "react-cookie"; import Banner from "./Banner"; export default function WelcomePage() { const [cookies, setCookie] = useCookies(["banner-seen"]); const handleBannerClose = () => { setCookie("banner-seen", true); }; return ( <CookiesProvider> <main> {!cookies["banner-seen"] && <Banner onClose={handleBannerClose} />} <div>Welcome to Alicante!</div> </main> </CookiesProvider> ); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import { useCookies, CookiesProvider } from "react-cookie"; <CookiesProvider> </CookiesProvider> 1 import Banner from "./Banner"; 2 3 export default function WelcomePage() { 4 const [cookies, setCookie] = useCookies(["banner-seen"]); 5 6 const handleBannerClose = () => { 7 setCookie("banner-seen", true); 8 }; 9 10 return ( 11 12 <main> 13 {!cookies["banner-seen"] && <Banner onClose={handleBannerClose} />} 14 <div>Welcome to Alicante!</div> 15 </main> 16 17 ); 18 } 19
  • 33. import { useCookies, CookiesProvider } from "react-cookie"; import Banner from "./Banner"; export default function WelcomePage() { const [cookies, setCookie] = useCookies(["banner-seen"]); const handleBannerClose = () => { setCookie("banner-seen", true); }; return ( <CookiesProvider> <main> {!cookies["banner-seen"] && <Banner onClose={handleBannerClose} />} <div>Welcome to Alicante!</div> </main> </CookiesProvider> ); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import { useCookies, CookiesProvider } from "react-cookie"; <CookiesProvider> </CookiesProvider> 1 import Banner from "./Banner"; 2 3 export default function WelcomePage() { 4 const [cookies, setCookie] = useCookies(["banner-seen"]); 5 6 const handleBannerClose = () => { 7 setCookie("banner-seen", true); 8 }; 9 10 return ( 11 12 <main> 13 {!cookies["banner-seen"] && <Banner onClose={handleBannerClose} />} 14 <div>Welcome to Alicante!</div> 15 </main> 16 17 ); 18 } 19 {!cookies["banner-seen"] && <Banner onClose={handleBannerClose} />} import { useCookies, CookiesProvider } from "react-cookie"; 1 import Banner from "./Banner"; 2 3 export default function WelcomePage() { 4 const [cookies, setCookie] = useCookies(["banner-seen"]); 5 6 const handleBannerClose = () => { 7 setCookie("banner-seen", true); 8 }; 9 10 return ( 11 <CookiesProvider> 12 <main> 13 14 <div>Welcome to Alicante!</div> 15 </main> 16 </CookiesProvider> 17 ); 18 } 19
  • 34. import { useCookies, CookiesProvider } from "react-cookie"; import Banner from "./Banner"; export default function WelcomePage() { const [cookies, setCookie] = useCookies(["banner-seen"]); const handleBannerClose = () => { setCookie("banner-seen", true); }; return ( <CookiesProvider> <main> {!cookies["banner-seen"] && <Banner onClose={handleBannerClose} />} <div>Welcome to Alicante!</div> </main> </CookiesProvider> ); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 import { useCookies, CookiesProvider } from "react-cookie"; <CookiesProvider> </CookiesProvider> 1 import Banner from "./Banner"; 2 3 export default function WelcomePage() { 4 const [cookies, setCookie] = useCookies(["banner-seen"]); 5 6 const handleBannerClose = () => { 7 setCookie("banner-seen", true); 8 }; 9 10 return ( 11 12 <main> 13 {!cookies["banner-seen"] && <Banner onClose={handleBannerClose} />} 14 <div>Welcome to Alicante!</div> 15 </main> 16 17 ); 18 } 19 {!cookies["banner-seen"] && <Banner onClose={handleBannerClose} />} import { useCookies, CookiesProvider } from "react-cookie"; 1 import Banner from "./Banner"; 2 3 export default function WelcomePage() { 4 const [cookies, setCookie] = useCookies(["banner-seen"]); 5 6 const handleBannerClose = () => { 7 setCookie("banner-seen", true); 8 }; 9 10 return ( 11 <CookiesProvider> 12 <main> 13 14 <div>Welcome to Alicante!</div> 15 </main> 16 </CookiesProvider> 17 ); 18 } 19 const handleBannerClose = () => { setCookie("banner-seen", true); }; import { useCookies, CookiesProvider } from "react-cookie"; 1 import Banner from "./Banner"; 2 3 export default function WelcomePage() { 4 const [cookies, setCookie] = useCookies(["banner-seen"]); 5 6 7 8 9 10 return ( 11 <CookiesProvider> 12 <main> 13 {!cookies["banner-seen"] && <Banner onClose={handleBannerClose} />} 14 <div>Welcome to Alicante!</div> 15 </main> 16 </CookiesProvider> 17 ); 18 } 19
  • 35.
  • 36. It would be better to use storage instead of cookies. You don't need the info on the server.
  • 37.
  • 38. Use camelCase for the cookie naming, ok?
  • 39.
  • 40. Are you serious with keeping this in the cookies?!
  • 41. Do you even imagine the impact the context has on the app? 🤦
  • 42. import { useState } from "react"; import Banner from "./Banner"; export default function WelcomePage() { const [bannerSeen, setBannerSeen] = useState( JSON.parse(localStorage.getItem("bannerSeen") ?? "false") ); const handleBannerClose = () => { setBannerSeen(true); localStorage.setItem("bannerSeen", "true"); }; return ( <main> {!bannerSeen && <Banner onClose={handleBannerClose} />} <div>Welcome to Alicante!</div> </main> ); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
  • 43. import { useState } from "react"; import Banner from "./Banner"; export default function WelcomePage() { const [bannerSeen, setBannerSeen] = useState( JSON.parse(localStorage.getItem("bannerSeen") ?? "false") ); const handleBannerClose = () => { setBannerSeen(true); localStorage.setItem("bannerSeen", "true"); }; return ( <main> {!bannerSeen && <Banner onClose={handleBannerClose} />} <div>Welcome to Alicante!</div> </main> ); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 const [bannerSeen, setBannerSeen] = useState( JSON.parse(localStorage.getItem("bannerSeen") ?? "false") ); const handleBannerClose = () => { setBannerSeen(true); localStorage.setItem("bannerSeen", "true"); }; import { useState } from "react"; 1 import Banner from "./Banner"; 2 3 export default function WelcomePage() { 4 5 6 7 8 9 10 11 12 13 return ( 14 <main> 15 {!bannerSeen && <Banner onClose={handleBannerClose} />} 16 <div>Welcome to Alicante!</div> 17 </main> 18 ); 19 } 20
  • 44.
  • 45. You probably don't know about more advanced concepts like the new React hook that you could use - useSyncExternalStore.
  • 46. import { useSyncExternalStore } from "react"; import Banner from "./Banner"; const subscribeToLocalStorage = (callback: () => void) => { window.addEventListener("storage", callback); return () => { window.removeEventListener("storage", callback); }; }; const getLocalStorageSnapshot = () => localStorage.getItem("bannerSeen"); export default function WelcomePage() { const bannerSeen = useSyncExternalStore( subscribeToLocalStorage, getLocalStorageSnapshot ); const handleBannerClose = () => { localStorage.setItem("bannerSeen", "true"); }; return ( <main> {bannerSeen !== "true" && <Banner onClose={handleBannerClose} />} <div>Welcome to Alicante!</div> </main> ); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
  • 47. import { useSyncExternalStore } from "react"; import Banner from "./Banner"; const subscribeToLocalStorage = (callback: () => void) => { window.addEventListener("storage", callback); return () => { window.removeEventListener("storage", callback); }; }; const getLocalStorageSnapshot = () => localStorage.getItem("bannerSeen"); export default function WelcomePage() { const bannerSeen = useSyncExternalStore( subscribeToLocalStorage, getLocalStorageSnapshot ); const handleBannerClose = () => { localStorage.setItem("bannerSeen", "true"); }; return ( <main> {bannerSeen !== "true" && <Banner onClose={handleBannerClose} />} <div>Welcome to Alicante!</div> </main> ); } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 const bannerSeen = useSyncExternalStore( subscribeToLocalStorage, getLocalStorageSnapshot ); import { useSyncExternalStore } from "react"; 1 import Banner from "./Banner"; 2 3 const subscribeToLocalStorage = (callback: () => void) => { 4 window.addEventListener("storage", callback); 5 return () => { 6 window.removeEventListener("storage", callback); 7 }; 8 }; 9 10 const getLocalStorageSnapshot = () => localStorage.getItem("bannerSeen"); 11 12 export default function WelcomePage() { 13 14 15 16 17 18 const handleBannerClose = () => { 19 localStorage.setItem("bannerSeen", "true"); 20 }; 21 22 return ( 23 <main> 24 {bannerSeen !== "true" && <Banner onClose={handleBannerClose} />} 25 <div>Welcome to Alicante!</div> 26 </main> 27 ); 28 } 29
  • 48.
  • 49. The hook is especially useful when you want to subscribe to some external store changes.
  • 50. Also, storage event does not fire when changes to the storage are made on the same page, so you would still need state.
  • 51.
  • 52. Wow! I thought React 18 was like Nessie - everyone talks about it, but no one has seen it!
  • 53. Dan would be proud of you!
  • 54. Just remember to still update state when user closes the banner.
  • 62. Negative Neutral Positive Codeprotection Revenge Showingoff Duty Knowledge sharing Personalgrowth Empathy Fun
  • 64.
  • 65.
  • 66.
  • 67.
  • 68. Memes