You can use state in App component which you can change it inside Tools and new state pass to DrawingBoard,

class App extends React.Component {
  constructor() {
    super();

    this.state = {
      styledata: {}
    };
  }

  getFormData(name, value) {
    this.setState({
      styledata: { [name]: value }
    })
  }

  render() {
    return <div className="main-container">
      <DrawingBoard styledata={ this.state.styledata } />
      <Tools data={ this.getFormData.bind(this) } />
    </div>
  }
}

class Tools extends React.Component {
  getData() {
    // Load data
    // 
    this.props.data('color', 'red');
  }

  render() {
    return <div>
      <button onClick={ this.getData.bind(this) }>Change Data</button>
    </div>
  }
}

class DrawingBoard extends React.Component {
  render() {
    return <div>
      <h1 style={ this.props.styledata }>DrawingBoard</h1>
    </div>
  }
}

Example

Answer from Oleksandr T. 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.
🌐
Stack Overflow
stackoverflow.com › questions › 68458702 › how-to-share-a-variable-across-components-in-reactjs
How to share a variable across components in ReactJS?
Class PatterComponent extends React.Component { render(){ return{ <> <App globalVariable="value"/> <Test globalVariable="value"/> </> } } }
Discussions

reactjs - React Share variables between components - Stack Overflow
I have three Components. App is the Parent component. Tools and DrawingBoard are child Components. I want to transfer Data between the Tools and DrawingBoard Component. export default class App ex... More on stackoverflow.com
🌐 stackoverflow.com
May 14, 2016
reactjs - How can we share a state variables between two React components on the same page? - Stack Overflow
Seems like a redundant thing to do, as the variable success measures the success of not the individual instance, but the combined success of all the instances. It seems weird to send the same value through each of the TextInput instances! 2020-09-22T05:40:04.173Z+00:00 ... I am not getting a clear picture of your setup, so it might be helpful if you can share your actual code. If there are multiple components, then I believe that the only way in react ... More on stackoverflow.com
🌐 stackoverflow.com
How to share a specific variable between different react components
//history const [items, setItems] = React.useState([]); const handledata = () => { localStorage.getItem(key); }; Complete code of both files https://github.com/Megahedron69/testrep ... You're best option is to decouple localstorage from both the components & make a it a separate module or a class. Then you can access it in both the files. ... If you don't want to do that - Lifting the state up is the best possible solution when want to share data between ... More on stackoverflow.com
🌐 stackoverflow.com
How Pass Data Between Components In React,Typescript,Class Component
Hello all i need pass data from Parent to child but i cant find a useful documentation for Class component to do this (maybe im bad on searching)… More on reddit.com
🌐 r/react
4
5
April 16, 2023
🌐
The Odin Project
theodinproject.com › lessons › node-path-react-new-passing-data-between-components
React - Passing Data Between Components
Using data to create customizable reusable components. In React, data is transferred from parent components to child components via props. This data transfer is unidirectional, meaning it flows in only one direction.
🌐
Medium
medium.com › @zachlandis91 › react-share-global-data-between-components-without-props-9f24abbcf208
React: Share “Global” Data Between Components Without Props | by Zach Landis | Medium
March 20, 2023 - Instead, you’d define that variable globally so it can be accessed anywhere. Thinking back to our example of passing props from Events > EventList > EventPage: Let’s say we want to add a ‘User’ component so that a client can log in and ‘Join’ events on the app for other users to see.
🌐
Pluralsight
pluralsight.com › tech insights & how-to guides › tech guides & tutorials
How to Pass Data between React Components | Pluralsight
May 29, 2020 - Use the variable this.props.dataFromParent to obtain the data passed from parent to child. class Child2 extends React.Component { render() { return ( <div> Data from parent is:{this.props.dataFromParent} </div> ); } }
Find elsewhere
🌐
Medium
medium.com › coding-in-depth › reactjs-share-data-between-the-components-de492b129086
ReactJS: Share data between the components | by Coding In depth | Coding In Depth | Medium
May 30, 2020 - From the child component add the product name, code, and description and display value in JSON form in the parent component. Demo screen looks like the below screenshot. ... Writing about Angular, React, JavaScript, Java, C#, NodeJS, AWS, MongoDB, and Redis related articles.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-pass-data-from-one-component-to-other-component-in-reactjs
How to Pass Data from One Component to Another Component in ReactJS? | GeeksforGeeks
When you need to pass data between sibling components (components that share the same parent), the best way is to use their common parent component as a mediator. The parent component can manage the shared state and pass it down to both child ...
Published   March 24, 2025
🌐
Squash
squash.io › sharing-variables-between-components-in-reactjs
Sharing Variables Between Components in ReactJS - Squash.io
December 20, 2023 - 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
🌐
freeCodeCamp
freecodecamp.org › news › pass-data-between-components-in-react
How to Pass Data and Events Between Components in React
June 8, 2021 - Next, in the parent component, accept this data in the childToParent function as a parameter. Then set the data using the useState hook. import './App.css'; import { useState } from 'react'; import Child from './Child'; function Parent() { const [data, setData] = useState(''); const childToParent = (childdata) => { setData(childdata); } return ( <div className="App"> <div> <Child/> </div> </div> ); } export default Parent; Next, show that data variable in the return function.
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
}
🌐
DEV Community
dev.to › turpp › passing-data-between-react-components-af7
Passing Data Between React Components - DEV Community
July 18, 2021 - React utilizes reusable components. This allows you to reuse your code, control how the components update, and control how they communicate with each other. Props allows us to pass data between React components.
🌐
YouTube
youtube.com › arslan
How to Pass Data Between Components In ReactJS - YouTube
What's up y'all in this video we'll learn how to pass data between components quite quickly. I hope this video helps you out :DPlease don't forget Like, Comm...
Published   December 20, 2021
Views   28K
🌐
Medium
trujillo9616.medium.com › how-to-pass-data-between-react-components-4eecae32e194
How to Pass Data Between React Components | by Adrian Trujillo Duron | Medium
December 7, 2021 - The function setMessage is used to update the variable’s value. The way we are going to make this work is passing this updater function to the child as props, so when we call to it from the child component the value will update in the parent component.
🌐
Codementor
codementor.io › community › best possible way to pass value within components in react
Best Possible way to pass value within components in React | Codementor
January 10, 2024 - Context provides a way to share values like a theme, locale, or authentication status between components without having to explicitly pass a prop through every level of the tree. For example: const MyContext = React.createContext(); // Parent ...
🌐
Pragimtech
pragimtech.com › blog › reactjs › interaction-between-components-in-react
How to Pass data between Components in React
Lets Open Index.js file, Create Employee Component which will display Employee Details. To save our time, I have kept the Code ready by copying from out last sessions and pasting it here. class Employee extends React.Component{ constructor(props){ super(props); } render(){ return <div> <h1>Employee Component...</h1> <p> <label>Id : <b>{this.props.Id}</b></label> </p> <p> <label>Name : <b>{this.props.Name}</b></label> </p> <p> <label>Location : <b>{this.props.Location}</b></label> </p> <p> <label>Total Salary : <b>{this.props.Salary}</b></label> </p> </div> } }
🌐
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 - Inside of Navigation, import the useContext Hook from React and UserContext from the component directory. Then call useContext using UserContext as an argument. Unlike the UserContext.Provider, you do not need to render UserContext in the JSX. The Hook will return the data that you provided in the value prop. Save the data to a new variable called user, which is an object containing name and favorites.
🌐
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 - Learn how to use React Context to share data between components without prop drilling, simplifying state management in your React applications.