Skip to content

Instantly share code, notes, and snippets.

View jogilvyt's full-sized avatar

Jack Taylor jogilvyt

View GitHub Profile
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">
function decisionMaker() {
const rand = Math.random();
if (rand < 0.3) {
return true;
}
if (rand > 0.7) {
return false;
}
return;
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";
}
function stringToBool(str) {
const boolStrings = {
"true": true,
"false": false,
};
return boolStrings[str] ?? "String is not a boolean value";
}
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";
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";
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") {
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;
}
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;
}
const Item = ({ params }) => {
const [data, setData] = useState(null);
useEffect(() => {
const res = axios.get('/some/url', { params });
setData(res);
}, [params]);
}