ZeeCoder / use-resize-observer

A React hook that allows you to use a ResizeObserver to measure an element's size.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Defaults are unnecessary code

Merri opened this issue · comments

I'm wondering about the defaults, because they seem to provide nothing of value that can't be done with just JavaScript:

const { ref, width = 100, height = 50 } = useResizeObserver()

This gives 100 x 50 until client side code kicks in.

It would make sense to encourage people to use JS features and keep hook's feature set and size as small as possible. (Unless I'm wrong here and I'm simply used to some extra feature not commonly available in most codebases.)

Yeah when I switched to returning an object instead of an array I didn't consider this possibility, but I think you're right. 🤔

You can do it with arrays, too!

const [ref, width = 100, height = 50] = useOlderResizeObserver()

Ah, good to know!