jungsoft / frontend-style-guide

Our frontend style guide
MIT License
16 stars 3 forks source link

Remove suggested use of curried functions from style guide #6

Open dylan1p opened 3 years ago

dylan1p commented 3 years ago

After reading through the style guide I discovered something small in the following section.

The suggested format above actually calls the function on every re-render anyways, so it's really creating more work.

I created a small JSFiddle to demonstrate this in action - as the component re-renders, the function is also re-created.

If we would like to avoid functions re-creating on each re-render we can use React useCallback, but only where it is really necessary. The following article goes more into detail about when it may be necessary to use useCallback or useMemo.

If we agree on removing this from the style guide I can submit a PR.

gabrielpra1 commented 3 years ago

Good catch! That is indeed wrong.

The question now is if we should:

  1. still prefer to go for curried functions because of readability
  2. prefer to avoid curried functions because of readability
  3. leave it open and remove the section

What do you think?