Skip to content

Instantly share code, notes, and snippets.

View AbdelrhmanAmin's full-sized avatar
🐺

Abdo Amin AbdelrhmanAmin

🐺
  • Frontend Dev
  • Egypt, Alexandria.
View GitHub Profile
Slayer's Testament I
In the first age, in the first battle, when the shadows first lengthened, one stood. Burned by the embers of Armageddon, his soul blistered by the fires of Hell and tainted beyond ascension, he chose the path of perpetual torment. In his ravenous hatred he found no peace; and with boiling blood he scoured the Umbral Plains seeking vengeance against the dark lords who had wronged him. He wore the crown of the Night Sentinels, and those that tasted the bile of his sword named him... the Doom Slayer.
Slayer's Testament II
Tempered by the fires of Hell, his iron will remained steadfast through the passage that preys upon the weak. For he alone was the Hell Walker, the Unchained Predator, who sought retribution in all quarters, dark and light, fire and ice, in the beginning and the end, and he hunted the slaves of Doom with barbarous cruelty; for he passed through the divide as none but demon had before.
// Pop quiz! What gets logged?
var o = {
[console.log('before')]: 4,
foo: (function () {
console.log('nope :(');
throw 'nope'
})(),
[console.log('after')]: 4
@AbdelrhmanAmin
AbdelrhmanAmin / DynamicRoutesManager.js
Last active September 1, 2022 10:34
404 error boundary for Dynamic routes or I'd rather say: Server-side-like fetching before entering a route.
// The problem is that I did have dynamic pages with things like `:id`, `:page`...etc
// and if someone decided to manipulate the url and enter a random id, the app would show the page but of course it would be broken.
// So I decided to create a wrapper component to manager to fetch the server and check if the id is valid. You can tweak this code to your own needs..
export const DynamicRouteManager = ({ children, fetcher }) => {
const flags = useRef({
isFirstRender: true,
didValidate: false,
});
const invalidRoutes = useRef([]);
@AbdelrhmanAmin
AbdelrhmanAmin / Collapse.jsx
Last active March 25, 2022 06:13
JavaScript dynamic max height transition
const INITIAL_MAX_HEIGHT = 10000;
const Collapse = ({ children }) => {
const collapseMenuRef = React.useRef(null);
const isFirstRender = React.useRef(true);
const maxHeightRef = React.useRef(INITIAL_MAX_HEIGHT);
const [isOpen, setOpen] = React.useReducer((state) => !state, false);
React.useEffect(() => {
if (collapseMenuRef.current && !isFirstRender.current) {
if (