🌐
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 - 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 ...
Discussions

One shared instance between multiple React components
If I wanted to share a single instance of my state machine in multiple React components, how would I go about it? The way I see it there are two possible solutions: A standard file with a state mac... More on github.com
🌐 github.com
5
3
reactjs - How can we share a state variables between two React components on the same page? - Stack Overflow
If there are multiple components, then I believe that the only way in react to share the states is by binding it to the props. If it is a dynamic and complex application which you are building, then you can also have a look at react context api or redux to have a global and unified state tree which can be shared between ... More on stackoverflow.com
🌐 stackoverflow.com
how to you share state between sibling components?
You need to research the concept of 'lifting state'. https://reactjs.org/docs/lifting-state-up.html The parent component can hold the state of its' children, in this case the sibling components you want to share data between. The parent will provide its' state to the children components as props. The parent can also pass functions down as props that will allow the children to update the shared state. When a child updates the parent's state, the new values will propagate to the other sibling through its' own props. There is absolutely no need for Context or Redux here. When I'm trying to solve a problem, I'm mindful if things are getting too complex, as it's usually an indication I'm doing it wrong. Hope this helps. More on reddit.com
🌐 r/reactjs
16
0
January 31, 2023
The most challenging thing for me about React is sharing state variables between components.
I don’t think people should be recommending state libraries and instead OP needs to understand the pattern of lifting state and managing state with just react. Edit: incorrectly referred to lifting state as hoisting More on reddit.com
🌐 r/reactjs
102
118
June 27, 2023
🌐
DEV Community
dev.to › kimbi619 › how-to-send-data-state-and-props-between-unrelated-components-in-react-51a1
How to send data (state and props) between unrelated components in react - DEV Community
April 19, 2021 - Declaring using the useState method in react, you can create the data that you want to pass to the different components after importing the createContext method in react as in the first line.
🌐
JavaScript in Plain English
javascript.plainenglish.io › sharing-state-between-react-components-8c138c505e36
How To Share State Between React Components | by Joe Bologna | JavaScript in Plain English
November 24, 2020 - The Child components will just ... say the parent wants to access the counter. This can be accomplished using global state managed by the Child component....
🌐
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 - 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.
🌐
3D Bay
clouddevs.com › home › react guides › how to share state between components?
How to share state between components?
November 10, 2023 - With a combination of `React.createContext` and the `useContext` hook, components can subscribe to context changes and access shared state seamlessly. State Management Libraries: In larger applications with more complex state logic, external state management solutions like Redux or MobX can be employed.
🌐
freeCodeCamp
freecodecamp.org › news › where-do-i-belong-a-guide-to-saving-react-component-data-in-state-store-static-and-this-c49b335e2a00
Where to Hold React Component Data: state, store, static, and this
August 13, 2016 - The important thing to know about local state is that when a state value changes, it triggers a re-render. This state can be passed down to children as props, which allows you to separate your components between smart ...
🌐
NamasteDev
namastedev.com › home › react › state sharing between components in react
State Sharing Between Components in React - NamasteDev Blogs
June 14, 2025 - In this example, both ChildA and ChildB can access and share the state defined in ParentComponent. ChildA can update the state, which reflects in ChildB. The Context API is a powerful feature that allows you to create global state accessible to any component, regardless of its position in the tree. This method is particularly useful for deeply nested components. import React, { createContext, useContext, useState } from 'react'; // Create a Context const MyContext = createContext(); const ParentComponent = () => { const [value, setValue] = useState('Shared Value'); return ( <MyContext.Provider
Find elsewhere
🌐
NamasteDev
namastedev.com › blog › state-sharing-between-components-in-react-4
State Sharing Between Components in React
Namastedev's Featured Post From Lag to Lightning-Fast: Namastedev’s API TransformationBy akshay Sometimes, the simplest solutions are the most effective. This applies to everyday life problems as well as technical ones. Today, I’ll share a common challenge we faced at our newly developed ...
🌐
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 ...
🌐
Squash
squash.io › sharing-variables-between-components-in-reactjs
Sharing Variables Between Components in ReactJS
The store holds the shared data in the application state. The ComponentA dispatches an action to set the data in the store when the button is clicked. The ComponentB accesses the shared data from the store using the useSelector hook and displays it in a paragraph element. The shared data is now accessible and synchronized between the non-related components. - Medium - Sharing Variables Between React Components
🌐
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 - In this snippet, the ParentComponent has a piece of state called parentState that it passes to the ChildComponent as a prop. The ChildComponent can then use this state in its render output. This is the most common way to share data between components in React.
🌐
DEV Community
dev.to › kenbaz › sharing-data-between-components-in-react-9hn
Sharing Data Between Components In React - DEV Community
June 17, 2024 - In the code example above, state has been moved from the Counter component up to the parent MyApp component which then passes the state back to the Counter component as props. Now both the counter components nested inside MyApp component share the same state and as such will update together. This brings us to the end of this article which is about sharing data between components in React.
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › reactjs-state
ReactJS State - GeeksforGeeks
We are using the ES6 thick arrow function format to take the previous state and props of the component as parameters and are updating the counter. The same can be written using the default functional way as follows. ... // Filename - index.js import React from "react"; import ReactDOM from "react-dom/client"; class App extends React.Component { constructor(props) { super(props); this.state = { count: 0, }; } increment = () => { this.setState((prevState) => ({ count: prevState.count + 1, })); }; decrement = () => { this.setState((prevState) => ({ count: prevState.count - 1, })); }; render() { r
Published   January 15, 2026
Top answer
1 of 4
1

In this case, if you have given a pascal case naming for the text input such as function TextInput(){...} , then react will consider this as a separate component even if this is defined in the same file. This is why the state variables of the App component are not within the scope of TextInput

You can mitigate this by following either of the following approcahes,

  • Make text input a normal function which returns the JSX
function textInput(){
 // the state variable 'success' and 'setSuccess' will be normally accessible here
 return(
   <div>
      <input type="text" />
   <div>
 )
}

//return for the 'App' component

return(
   <>
     {textInput()}
   </>
)

  • Passing the state as props to the TextInput component

    If you follow this approach, then you can have the TextInput component in a separate file as well

//parent 'App' component

function App(){
  const [success, setSuccess] = useState(false);

  return(
    <>
       <TextInput success={success} setSuccess={setSuccess}></TextInput>
    </>
  )
}

function TextInput(props){
   const {success, setSuccess} = props;
   
   // In here you can refer success and setSuccess normally as you would even if this is in a separate file
}
2 of 4
0

To share the state you need to declare the state in the parent component (App in your case) and send it to the child component (TextInput)

e.g.

function App() {
  const [success, setSuccess] = useState(false);

  ...

  return (
    <TextInput success={success} setSuccess={setSuccess} />
  );
}
function TextInput({success, setSuccess}) {
  // use success/setSuccess from props
}
🌐
CoreUI
coreui.io › answers › how-to-share-state-between-components-in-react
How to share state between components in React · CoreUI
October 16, 2025 - 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, ...
🌐
Medium
medium.com › sky-one-engineering › sharing-state-between-components-using-hooks-f10adef01952
Sharing state between components using hooks. | by Vitor Vieria | Sky.One Engineering | Medium
January 20, 2020 - But to this work, I need to import it inside of homeContainer and pass the state as props to starsFilter component. ... Ok, let’s build the movies catalog now with the same approach. ... I put some grids to make it responsible to have a better visual. Now, let’s import inside of homeContainer, pass the state as props and take a look at the result. ... And the result is. the following ... This way you are able to share state between components without controlling everything in the parent component and you also remove all the logic for an external layer and the components stays just as views.
🌐
Developerway
developerway.com › posts › react-state-management-2025
React State Management in 2025: What You Actually Need
September 25, 2025 - It's just something that comes from overusing Redux in the past. Use React's useState or useReducer in this case. Shared state. This is the state that you want to share between different loosely related components.