- Which is better class component or functional component in React Native?
- Why functional components are better?
- In which of the following cases should you use higher-order components?
Which is better class component or functional component in React Native?
Class components are used as container components to handle state management and wrap child components. Functional components generally are just used for display purposes - these components call functions from parent components to handle user interactions or state updates.
Why functional components are better?
Easier to test: You don't have to worry about hidden state and there aren't as many side effects when it comes to functional components, so for every input, the functions will have exactly one output.
In which of the following cases should you use higher-order components?
We use higher order components to primarily reuse logic in React apps. However, they have to render some UI. Hence, HOCs are inconvenient when you want to share some non-visual logic. In such a case, React hooks seem to be a perfect mechanism for code reuse.