This file contains hidden or 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
const Modal = ({ header, body, onClose }) => { | |
return ( | |
<div className="Modal"> | |
<div className="Modal-Header"> | |
<h2>{header}</h2> | |
</div> | |
<div className="Modal-Body"> | |
<p>{body}</p> | |
</div> | |
<div className="Modal-Actions"> |
This file contains hidden or 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
function decisionMaker() { | |
const rand = Math.random(); | |
if (rand < 0.3) { | |
return true; | |
} | |
if (rand > 0.7) { | |
return false; | |
} | |
return; |
This file contains hidden or 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
function calculate(num1, num2, action) { | |
const actions = { | |
add: (a, b) => a + b, | |
subtract: (a, b) => a - b, | |
multiply: (a, b) => a * b, | |
divide: (a, b) => a / b, | |
}; | |
return actions[action]?.(num1, num2) ?? "Calculation is not recognised"; | |
} |
This file contains hidden or 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
function stringToBool(str) { | |
const boolStrings = { | |
"true": true, | |
"false": false, | |
}; | |
return boolStrings[str] ?? "String is not a boolean value"; | |
} |
This file contains hidden or 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
function getTranslationMap(rhyme) { | |
const rhymes = { | |
"apples and pears": "Stairs", | |
"hampstead heath": "Teeth", | |
"loaf of bread": "Head", | |
"pork pies": "Lies", | |
"whistle and flute": "Suit", | |
}; | |
return rhymes[rhyme.toLowerCase()] ?? "Rhyme not found"; |
This file contains hidden or 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
function getTranslation(rhyme) { | |
switch (rhyme.toLowerCase()) { | |
case "apples and pears": | |
return "Stairs"; | |
case "hampstead heath": | |
return "Teeth"; | |
case "loaf of bread": | |
return "Head"; | |
case "pork pies": | |
return "Lies"; |
This file contains hidden or 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
function getTranslation(rhyme) { | |
if (rhyme.toLowerCase() === "apples and pears") { | |
return "Stairs"; | |
} else if (rhyme.toLowerCase() === "hampstead heath") { | |
return "Teeth"; | |
} else if (rhyme.toLowerCase() === "loaf of bread") { | |
return "Head"; | |
} else if (rhyme.toLowerCase() === "pork pies") { | |
return "Lies"; | |
} else if (rhyme.toLowerCase() === "whistle and flute") { |
This file contains hidden or 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
const Item = ({ params }) => { | |
const prevParams = useRef(params); | |
const [data, setData] = useState(null); | |
useEffect(() => { | |
if (!isDeepEqual(prevParams.current, params)) { | |
const res = axios.get('/some/url', { params }); | |
setData(res); | |
prevParams.current = params; | |
} |
This file contains hidden or 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
const Item = ({ params }) => { | |
const hasFetchedData = useRef(false); | |
const [data, setData] = useState(null); | |
useEffect(() => { | |
if (!hasFetchedData.current) { | |
const res = axios.get('/some/url', { params }); | |
setData(res); | |
hasFetchedData.current = true; | |
} |
This file contains hidden or 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
const Item = ({ params }) => { | |
const [data, setData] = useState(null); | |
useEffect(() => { | |
const res = axios.get('/some/url', { params }); | |
setData(res); | |
}, [params]); | |
} |