score:1

import { createRef } from "react";
export default function App() {
  const renderTh = (data, index, ref) => {
    return (
      <th ref={ref} key={index} onClick={() => redColor(ref)}>
        {data}
      </th>
    );
  };

  const redColor = (ref) => {
    if (!ref.current) return;
    ref.current.style.color = "red";
  };

  const dataSet = ["one", "two", "three"];
  const refArray = [];
  return (
    <div className="App">
      <h1>Hello CodeSandbox</h1>
      <table>
        <thead>
          {dataSet.map((data, index) => {
            const ref = createRef();
            refArray[index] = ref;
            return renderTh(data, index, ref);
          })}
        </thead>
      </table>
    </div>
  );
}

Related Query

More Query from same tag