Explain the lifecycle of React hooks and how you optimize functional components to prevent unnecessary re-renders.