Keeping Focus in Place with Load-More Buttons
Opened this issue ยท 3 comments
AleksandrHovhannisyan commented
Keeping Focus in Place with Load-More Buttons
EllyLoel commented
Awesome post! Thanks for sharing ๐
jkettmann commented
Great blog post. Helped a lot. Only one suggestion: You can simplify the code a bit by using a ref callback. That way you don't need the useEffect
either ๐
const ResultGrid = (props) => {
const onMount = (ref) => {
if (ref) {
ref.focus();
}
}
return (
<>
<ol>
{props.results.map((result, i) => {
const isFirstNewResult = i === props.firstNewResultIndex;
return (
<li key={i} id={`result-${i}`}>
<a
ref={isFirstNewResult ? onMount : undefined}
AleksandrHovhannisyan commented
@jkettmann Clever, thanks for sharing! I'll see if I can get around to updating the article with that approach.