Hooks allow modules to alter and extend the behavior of Drupal core, or another module. They are one of the various ways that code components in Drupal can communicate with one another. Using hooks a module developer can change how core or another module works -- without changing the existing code.From an implementation perspective hooks are specially-named functions called at specific times to alter or add to the base behavior. There are many type of hooks but for this topic we will work on the hook_preprocess. This hook allows modules to preprocess theme variables for theme templates. It is called for all theme hooks implemented as templates, but not for theme hooks implemented as functions. hook_preprocess_HOOK() can be used to preprocess variables for a specific theme hook, whether implemented as a template or function.
Example:
Changing field template suggestions
From the get go, Drupal gives us lots of options for templates that each field can use. Sometimes, though, you may want to point multiple different (programmatically unrelated) fields to the same Twig template. A common use case that I personally employ on most projects is something like field__bare - a field template I create that has no wrapper divs, labels, or classes, but simply renders the field's contents. There are plenty of other design reasons that you might want different fields to point to the same template, though.