'MUI Material UI React Hook useTheme() is legacy, what is the alternative?

If the React Hook useTheme() is legacy, how can one access theme props outside of JSX and CSS and not by using sx prop?

For example, I have a more complex logic in a component and need to access my custom theme properties in some handlers, but I don’t want to use legacy APIs.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source