masakudamatsu / line-height-picker

A front-end web app that helps web designers/developers pick the best line-height value for their websites
https://line-height-picker.vercel.app
MIT License
1 stars 1 forks source link

Refactor getElementById() with the use of useRef #84

Open masakudamatsu opened 4 years ago

masakudamatsu commented 4 years ago

Read https://reactjs.org/docs/refs-and-the-dom.html carefully

masakudamatsu commented 4 years ago

To forward ref to a child component, we need

which will make the code complicated. In these cases, we keep using getElementById().

masakudamatsu commented 3 years ago

Now I know how to use React.forwardRef() and useImperativeHandle. So we will refactor getElementById().

masakudamatsu commented 3 years ago

Done for the x-height value box.

For the modular scale boxes, we cannot use forwardRef because we have two components to refer to.

Instead we will change the composition: