Names of Hooks
When it comes to naming Hooks, there is a convention that Hook functions should always be prefixed with use
, followed by the Hook name starting with a capital letter. For example: useState
, useEffect
, and useQuery
. This is important because, otherwise, we would not know which functions are Hooks, and which are not. Especially when automatically enforcing the rules of Hooks, we need to be able to know which functions are Hooks, so that we can make sure they are not being called conditionally or in loops.
It is best practice to name Hooks in such a way that they semantically make sense. For example, if you want to create a custom Hook for an input field, you would call it useInputField
. This ensures that when using the Hook it is immediately clear what that Hook will be useful for.
As we can see, naming conventions make our lives a lot easier: Knowing the difference between normal functions and Hooks makes it very easy to automatically enforce the...