#Does anyone know how I can refactor this?
1 messages · Page 1 of 1 (latest)
@red bramble Should be able do something like this:
function renderRow(row: Whatever[], css: string) {
return (
<div className={[css.keyboardRow, css].join(" ")}>
{row.map((character) => (
<div
className={css.keyboardButton}
onTouchStart={() => {
handleInputByAppending("mobile-keyboard", character);
}}
key={character}
>
{character}
</div>
))}
</div>
);
}
return <>
{renderRow(firstRow, css.keyboardRowOne)}
{renderRow(secondRow, css.keyboardRowTwo)}
{renderRow(thirdRow, css.keyboardRowThree)}
</>
Some people would make it its own component, and you could, but I don't know if it's necessary.