logo
React Hooks - Interview Questions and Answers
How do we share state logic between components?
We can share state logic between components in React using techniques such as prop drilling, lifting state up, or by using state management libraries like Redux or React Context.

* Prop Drilling : Pass state and functions down through props from parent to child components. This is suitable for simple applications with a shallow component tree.

* Lifting State Up : Move shared state and related functions to the nearest common ancestor component and pass them down as props to child components. This is effective for managing state across multiple related components.

* State Management Libraries : Use state management libraries like Redux or React Context for managing global state that needs to be accessed by multiple components across the application. These libraries provide centralized state management and make it easier to share state logic across components.