The dependency type between the components will define the best approach.

For instance, redux is a great option if you plan to have a central store. However other approaches are possible:

  • Parent to Child

    1. Props
    2. Instance Methods
  • Child to Parent

    1. Callback Functions
    2. Event Bubbling
  • Sibling to Sibling

    1. Parent Component
  • Any to Any

    1. Observer Pattern
    2. Global Variables
    3. Context

Please find more detailed information about each of the approaches here

Answer from Custodio on Stack Overflow
🌐
React
react.dev › learn › sharing-state-between-components
Sharing State Between Components – React
This principle is also known as having a “single source of truth”. It doesn’t mean that all state lives in one place—but that for each piece of state, there is a specific component that holds that piece of information. Instead of duplicating shared state between components, lift it up to their common shared parent, and pass it down to the children that need it.
🌐
DhiWise
dhiwise.com › post › The Ultimate Guide to Managing State Between Components in React
How to Manage State Between Components in React
April 2, 2025 - When multiple components need to ... ancestor. This pattern involves moving the state to a parent component and passing it down to the child components that need it, along with functions ......
People also ask

Can React Context replace state management libraries like Redux?
React Context can replace state management libraries for simple scenarios, but for complex state management, libraries like Redux might still be more appropriate.
🌐
pluralsight.com
pluralsight.com › tech insights & how-to guides › tech guides & tutorials
How to Use React Context to Share Data between Components | ...
What is React Context?
React Context is a built-in feature that allows you to pass data through a component tree without having to pass props down manually at every level.
🌐
pluralsight.com
pluralsight.com › tech insights & how-to guides › tech guides & tutorials
How to Use React Context to Share Data between Components | ...
When should I use React Context?
React Context is ideal for sharing global data like themes, user information, or settings across multiple components without prop drilling.
🌐
pluralsight.com
pluralsight.com › tech insights & how-to guides › tech guides & tutorials
How to Use React Context to Share Data between Components | ...
🌐
Medium
medium.com › actived › how-to-share-state-between-multiple-components-without-passing-them-in-props-or-using-a-library-224480a94cf1
How to share state between multiple components without passing them in props (React, Context API). | by John Doe | Active Developement | Medium
October 31, 2022 - For this example a first answer ... the callback down. The correct answer regardless of the complexity is “By using the context API of React”. It will keep all the logic around the shared state “recipes”...
🌐
React
legacy.reactjs.org › docs › lifting-state-up.html
Lifting State Up – React
In React, sharing state is accomplished by moving it up to the closest common ancestor of the components that need it. This is called “lifting state up”. We will remove the local state from the TemperatureInput and move it into the Calculator ...
Top answer
1 of 6
57

The dependency type between the components will define the best approach.

For instance, redux is a great option if you plan to have a central store. However other approaches are possible:

  • Parent to Child

    1. Props
    2. Instance Methods
  • Child to Parent

    1. Callback Functions
    2. Event Bubbling
  • Sibling to Sibling

    1. Parent Component
  • Any to Any

    1. Observer Pattern
    2. Global Variables
    3. Context

Please find more detailed information about each of the approaches here

2 of 6
31

What you want is to implement some object that stores your state, that can be modified using callback functions. You can then pass these functions to your React components.

For instance, you could create a store:

function Store(initialState = {}) {
  this.state = initialState;
}
Store.prototype.mergeState = function(partialState) {
  Object.assign(this.state, partialState);
};

var myStore = new Store();

ReactDOM.render(
  <FirstComponent mergeState={myStore.mergeState.bind(myStore)} />,
  firstElement
  );
ReactDOM.render(
  <SecondComponent mergeState={myStore.mergeState.bind(myStore)} />,
  secondElement
  );

Now, both the FirstComponent and SecondComponent instances can call this.props.mergeState({ . . .}) to assign state to the same store.

I leave Store.prototype.getState as an exercise for the reader.

Note that you can always pass the store (myStore) itself to the components; it just feels less react-y to do so.

Here is some more documentation that might be of interest:

React Docs: "Communicate Between Components"

For communication between two components that don't have a parent-child relationship, you can set up your own global event system. Subscribe to events in componentDidMount(), unsubscribe in componentWillUnmount(), and call setState() when you receive an event. Flux pattern is one of the possible ways to arrange this.

Top answer
1 of 10
164

If you are referring to component state, then hooks will not help you share it between components. Component state is local to the component. If your state lives in context, then useContext hook would be helpful.

Fundamentally, I think you misunderstood the line "sharing stateful logic between components". Stateful logic is different from state. Stateful logic is stuff that you do that modifies state. For e.g., a component subscribing to a store in componentDidMount() and unsubscribing in componentWillUnmount(). This subscribing/unsubscribing behavior can be implemented in a hook and components which need this behavior can just use the hook.

If you want to share state between components, there are various ways to do so, each with its own merits:

1. Lift State Up

Lift state up to a common ancestor component of the two components.

function Ancestor() {
    const [count, setCount] = useState(999);
    return <>
      <DescendantA count={count} onCountChange={setCount} />
      <DescendantB count={count} onCountChange={setCount} />
    </>;
  }

This state sharing approach is not fundamentally different from the traditional way of using state, hooks just give us a different way to declare component state.

2. Context

If the descendants are too deep down in the component hierarchy and you don't want to pass the state down too many layers, you could use the Context API.

There's a useContext hook which you can leverage on within the child components.

3. External State Management Solution

State management libraries like Redux or Mobx or Zustand. Your state will then live in a store outside of React and components can connect/subscribe to the store to receive updates.

2 of 10
96

It is possible without any external state management library. Just use a simple observable implementation:

function makeObservable(target) {
  let listeners = []; // initial listeners can be passed an an argument aswell
  let value = target;

  function get() {
    return value;
  }

  function set(newValue) {
    if (value === newValue) return;
    value = newValue;
    listeners.forEach((l) => l(value));
  }

  function subscribe(listenerFunc) {
    listeners.push(listenerFunc);
    return () => unsubscribe(listenerFunc); // will be used inside React.useEffect
  }

  function unsubscribe(listenerFunc) {
    listeners = listeners.filter((l) => l !== listenerFunc);
  }

  return {
    get,
    set,
    subscribe,
  };
}

And then create a store and hook it to react by using subscribe in useEffect:

const userStore = makeObservable({ name: "user", count: 0 });

const useUser = () => {
  const [user, setUser] = React.useState(userStore.get());

  React.useEffect(() => {
    return userStore.subscribe(setUser);
  }, []);

  const actions = React.useMemo(() => {
    return {
      setName: (name) => userStore.set({ ...user, name }),
      incrementCount: () => userStore.set({ ...user, count: user.count + 1 }),
      decrementCount: () => userStore.set({ ...user, count: user.count - 1 }),
    }
  }, [user])

  return {
    state: user,
    actions
  }
}

And that should work. No need for React.Context or lifting state up

Find elsewhere
🌐
GitHub
github.com › betula › use-between
GitHub - betula/use-between: Sharing state between React components
For the same hook, the result of the call will be the same. So we can call one hook in different components and work together on one state. When updating the shared state, each component using it will be updated too.
Starred by 291 users
Forked by 15 users
Languages   TypeScript 98.7% | JavaScript 1.3% | TypeScript 98.7% | JavaScript 1.3%
🌐
DigitalOcean
digitalocean.com › community › tutorials › how-to-share-state-across-react-components-with-context
How To Share State Across React Components with Context | DigitalOcean
July 22, 2020 - In this tutorial, you’ll share state across multiple components using React context. React context is an interface for sharing information with other components without explicitly passing the data as props. This means that you can share information between a parent component and a deeply ...
🌐
Pluralsight
pluralsight.com › tech insights & how-to guides › tech guides & tutorials
How to Use React Context to Share Data between Components | Pluralsight
April 24, 2024 - A workaround for that is to have a dedicated Context/Provider for each functional section that share data between its own components. Then you will reduce the number of components rendering as you will only have updates on sub-trees of your app.
🌐
DEV Community
dev.to › bytebodger › hacking-react-hooks-shared-global-state-553b
Hacking React Hooks: Shared Global State - DEV Community
July 29, 2020 - I'm going to show a dead-simple, possibly "hacky", technique for sharing global state and stateful logic between functional components with Hooks. I've lost count of how many times I've heard, or read, that Hooks can be used to "share state between components". It feels to me like this has become a de facto mantra of the React/Hooks crowd.
🌐
Squash
squash.io › sharing-state-between-two-components-in-react-javascript
Sharing State Between Two Components in React JavaScript
April 8, 2024 - The ChildComponent uses the useContext hook to access the shared state and function from the context. The context API provides a convenient way to share state between components without the need for props drilling.
🌐
DEV Community
dev.to › sonaykara › reactjs-sharing-state-between-components-52pg
React.js : Sharing State Between Components - DEV Community
January 2, 2025 - To synchronize the state of two components, a shared state should be lifted to their nearest common parent and passed down to both components as props. Let's transfer the isActive state to the parent component and add isActive to the Panel's ...
🌐
Medium
medium.com › @marazzo94 › lifting-state-up-in-react-sharing-data-between-parent-and-child-componentsintroduction-54d43342c944
Lifting State Up in React: Sharing Data Between Parent and Child Components | by Marazzo | Medium
April 26, 2023 - When the button is clicked, the onIncrement function is called, which updates the state in the `Parent component using the setCount function. This updates the state in the Parent component, and the updated count value is passed down to the Child component as a prop. ... Another way to lift state up in React is by using context. Context provides a way to share data between components without having to pass it down through props explicitly.
🌐
Medium
medium.com › @re.etp › how-to-use-react-context-to-share-state-between-components-950a32fad1e6
How to Use React Context to Share State Between Components | by Reet Pratayay | Medium
March 28, 2023 - In this code, Component1 uses the useMerchantContext hook to access the shared state, and defines a handleClick function that updates the merchant data using the dispatch function provided by the context. The updated state is then used to render a button and display the merchant name. Component2 also uses the useMerchantContext hook to access the shared state, and displays the merchant address. Finally, the MerchantContextProvider is wrapped around the two child components in the App component. React’s Context API provides a powerful way to share data and state between components without the need for props drilling.
🌐
CoreUI
coreui.io › answers › how-to-share-state-between-components-in-react
How to share state between components in React · CoreUI
October 16, 2025 - From my expertise, the most effective approach is using lifted state for simple cases and Context API for complex shared state scenarios. This method provides clean data flow with proper state encapsulation and efficient re-rendering patterns. Use lifted state for simple sharing and Context API for complex state that needs to be accessed by multiple components. import { useState, createContext, useContext } from 'react' // Method 1: Lifting State Up function App() { const [sharedData, setSharedData] = useState({ count: 0, user: null }) return ( <div> <Header user={sharedData.user} /> <Counter
🌐
DEV Community
dev.to › betula › sharing-react-hooks-stateful-logic-between-components-1g3o
Sharing React hooks stateful logic between components - DEV Community
January 21, 2021 - When you want to separate your ... some of state parts or control functions to another component your need pass It thought React component props....
🌐
React
react.dev › learn › managing-state
Managing State – React
As your application grows, it helps to be more intentional about how your state is organized and how the data flows between your components. Redundant or duplicate state is a common source of bugs. In this chapter, you’ll learn how to structure your state well, how to keep your state update logic maintainable, and how to share state between distant components.
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › how-to-share-state-across-react-components-with-context
How to share state across React Components with context ? - GeeksforGeeks
July 23, 2025 - To share state across React Components with Context we will first create a context with createContext Method. Wrap the App component with Provider for supplying the State.