Do what you always do and use Amplify's helper methods for setup and teardown.
You need to understand the selector operators.
useCallback is for functions and useMemo is for results.
Once you learn this, you'll understand setState better.
You need to get the types right.
A higher-order component will do the job.