Custom Hooks are convient pain in the......

There is a tendency to confuse hooks with functions. Yet the key difference is hooks can use other hooks and functions can't. Hooks usually return something like an object or some JSX code. They can also perform a specific function. Take useState. This allows you to track and change the state in your ReactJS component or hook. Custom hooks work the same/. You can have a function called, useCallCenter, that does something and returns a call center object or some other JSX code.

Hooks can make coding things very tricky. Firstly, they can only be used in another ReactJS component or hook, and they must be at the top level of the component. No nesting, loops or conditionals. In fact, you can't even have a conditional that will terminate the code before they are run. Hooks must be run in the same order every time the component renders. This can limit their creation to very specific tasks only and their use sparingly.

I can't tell you how many times I've had to think up (ask Stack Overflow) how to avoid infinitely looping states. useEffect allows you to perform some task after the component has rendered, and will perform that task only when a supplied variable has been changed. Yet if that variable is created in the component then you will have an infinite loop. There is so much more I can complain about.


SIGH!

Post a Comment

Previous Post Next Post