Should I wrap every prop with useCallback or useMemo, when to use this hooks?

Not worth it, for multiple reasons:

  1. Even official docs say you should do it only when necessary.
  2. Keep in mind that premature optimization is the root of all evil 🙂
  3. It makes DX (developer experience) far worse: it’s harder to read; harder to write; harder to refactor.
  4. When dealing with primitives (like in your example) memoizing costs more CPU power than not doing it. A primitive value doesn’t have a concept of references, so there’s nothing to memoize in them. On the other hand, memoization itself (as any other hook) does require some tiny processing, nothing is for free. Even though it’s tiny, it’s still more than nothing (compared to just passing a primitive through), so you’d shoot your own foot with this approach.

To put all together – you’d waste more time typing all the hooks than a user would gain on having them in the application if you want to put them everywhere. The good old rule applies: Measure, then optimize.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)