My custom hook useTyper.jsuseTyper.js
ended up as a bit of a mess and hard to read.
It's mimicking a nested for-loop but using "React.useRef"sReact.useRef
s to hold on to index valuesthe indexes between renders. With index values I meanThe indexes are the current positions of the outer and inner loop (those, those often named ii
and jj
in a classictraditional nested for loop)loops.
One thing I'm particularly unhappy with is the naming of stringIdxstringIdx
and stringsIdxstringsIdx
. Any suggestion for a change?
useTyper.js:useTyper.js
For completion, this is the useIntervaluseInterval
hook being used by useTyper:
(useTyper
.
It can be referenced from one of Dan Abramovs blog posts.)
useInterval.js:
useInterval.js
Also, here'sHere is how the useTyperuseTyper
hook can be used:.