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 Icon({ i, char, reverse = false }) { | |
const padding = Array.from({ length: i }, (_, i) => ( | |
<span key={i}> </span> | |
)) | |
return reverse ? [char, ...padding] : [...padding, char] | |
} | |
function Happy({ i }) { | |
return <Icon i={i} char="ᕕ( ᐛ )ᕗ" /> | |
} |
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 MLetterInput = memo( | |
LetterInput, | |
({ value: _old }, { value: _new }) => _old === _new | |
) | |
//... Inside the render method of <Form/> | |
{Object.keys(alphabet).map((l, i) => | |
state.itMatters ? ( | |
<MLetterInput |
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
import { useEffect } from "react" | |
const TIMER_WINDOW = 20000 | |
const TYPING_DELAY = 20 | |
const MAX_LENGTH = 20 | |
export const useTyping = (setState) => | |
useEffect(() => { | |
const inputs = document.getElementsByClassName("input-letter") | |
Array.from(inputs).forEach((el, idx) => { |
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 Form({ state, setState }) { | |
const toggle = useCallback(() => { | |
setState(state => ({ ...state, itMatters: !state.itMatters })) | |
}) | |
const changeLetter = useCallback(l => e => | |
setState(state => ({ ...state, [l]: e.target.value })) | |
) | |
return ( | |
<form name="f"> | |
<h2>Does unnecessary re-rendering matter? </h2> |
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
class Solution: | |
I = 'I' | |
V = 'V' | |
X = 'X' | |
L = 'L' | |
C = 'C' | |
D = 'D' | |
M = 'M' | |
def intToRoman(self, num): | |
""" |