For child-parent communication you should pass a function setting the state from parent to child, like this


class Parent extends React.Component {
  constructor(props) {
    super(props)

    this.handler = this.handler.bind(this)
  }

  handler() {
    this.setState({
      someVar: 'some value'
    })
  }

  render() {
    return <Child handler = {this.handler} />
  }
}

class Child extends React.Component {
  render() {
    return <Button onClick = {this.props.handler}/ >
  }
}

This way the child can update the parent's state with the call of a function passed with props.

But you will have to rethink your components' structure, because as I understand components 5 and 3 are not related.

One possible solution is to wrap them in a higher level component which will contain the state of both component 1 and 3. This component will set the lower level state through props.

Answer from Ivan on Stack Overflow
🌐
React
react.dev › learn › sharing-state-between-components
Sharing State Between Components – React
Then pass the information down through props from their common parent. Finally, pass the event handlers down so that the children can change the parent’s state. It’s useful to consider components as “controlled” (driven by props) or “uncontrolled” (driven by state). ... These two inputs are independent. Make them stay in sync: editing one input should update the other input with the same text, and vice versa.
Discussions

React js change child component's state from parent component
In this way, whole Parent component is being re-render by which we loose efficiency. Can you please tell any way in which only Child component will update its State or Props (means re-render) without re-render of Parent component. More on stackoverflow.com
🌐 stackoverflow.com
React - Children Components modifying parents state?
Tell us what’s happening: I want to make sure I understand whats going on here. I understand that state can flow from Parent Components → Child Components when we render child components with state from the parent passe… More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
1
0
March 1, 2021
how to change the state of parent component from child Component if parent state is maintained using useStateHook
Hi Team, I have started using the hooks. And come across a scenario where i have to change the state of the parent component from the child component . But I am maintaining the parent component sta... More on github.com
🌐 github.com
18
February 15, 2019
How to update parent state on updating parent state?
Hi All, I’m trying to pass props from a parent component to a child component. If the parent component state updates, I am passing the updated state to the child component as props, and trigger a re-render of child component. If the onclick function trigger in child component then parent ... More on forum.rescript-lang.org
🌐 forum.rescript-lang.org
0
0
April 4, 2023
🌐
Reddit
reddit.com › r/reactjs › how to change parent state from child component?
r/reactjs on Reddit: How to change parent state from child component?
July 7, 2023 -

Hello folks,

how can i change the state of a parent component inside a child component?

import React, { useState } from "react";
import Login from './components/Login/Login.js'; import './App.css';

function App() { 
    const [loginStatus, setloginStatus] = useState(false);

    return ( 
        <div className="App"> 
            <Login /> 
        </div> 
    ); 
}
export default App;

Specifically i am trying to do some login functionality. Based on the loginStatus i want to render the Login-Component. Inside the Login-Component i want to set loginStatus = true, when user/pw is correct. Can i maybe pass the setloginStatus to the Login-Component, or something?

Are there any keywords i can look for in the React documentation?

🌐
Medium
medium.com › @kyledavelaar › updating-parent-component-state-from-children-components-in-react-2ead9b9cec9f
Updating Parent Component State from Children Components in React | by Kyle Davelaar | Medium
April 7, 2017 - You can literally think of this.props.view() as being equivalent to changeView() in the parent component. This means that we can now change the state of the Parent component from the child component!
🌐
Our Code World
ourcodeworld.com › articles › read › 409 › how-to-update-parent-state-from-child-component-in-react
How to update parent state from child component in React | Our Code World
March 11, 2017 - To achieve the child-parent communication, you can send a function as a Prop to the child component. This function should do whatever it needs to in the component e.g change the state of some property.
Find elsewhere
🌐
GitHub
github.com › reactjs › react.dev › issues › 1689
how to change the state of parent component from child Component if parent state is maintained using useStateHook · Issue #1689 · reactjs/react.dev
February 15, 2019 - I have started using the hooks. And come across a scenario where i have to change the state of the parent component from the child component . But I am maintaining the parent component state using useState hook . So i am not getting access to the function to change this state from the child component .
Author   girishts
🌐
Jscrambler
jscrambler.com › blog › how-to-update-child-and-parent-components-in-react-js
How to Update Child and Parent Components in React.js | Blog
February 4, 2025 - Here, we just used the updated child state from the parent component. You can even pass the method to the child component and try to update the `childState` from the child component itself. In this tutorial, you learned how to update states in your react components, how to update the parent component from the child component, and vice versa.
🌐
TutorialsPoint
tutorialspoint.com › how-to-set-parent-state-from-children-component-in-reactjs
How to set Parent State from Children Component in ReactJS?
October 26, 2023 - We can set the parent state from the children component in function components by passing the state handle function as a prop of the child component. Whenever we pass any function as a component prop, we can execute it from the child component, even if it is defined in the parent component.
🌐
Chafikgharbi
chafikgharbi.com › react-update-parent-child-state
Update Parent and Child Components State in React.js | Chafik Gharbi
May 8, 2020 - class ParentComponent extends React.Component { constructor(props) { super(props) this.state = { value: "Foo" } } render() { return ( <div> {this.state.value} <ChildComponent ref={ref => (this.child = ref)} setState={state => this.setState(state)} /> <button onClick={() => this.child.setState({ value: "Foo" })}> Update child state </button> </div> ) } }
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-update-parent-state-in-reactjs
How to Update Parent State in ReactJS ? | GeeksforGeeks
October 1, 2024 - To update parent state in React we will pass a function as a prop to the child component. Then trigger the update funtion from the child component and the state in the parent component will be directly updated.
🌐
TutorialsPoint
tutorialspoint.com › how-to-update-parent-state-in-reactjs
How to update parent state in ReactJS?
March 18, 2021 - To update the parent state from the children component, either we can use additional dependencies like Redux or we can use this simple method of passing the state of the parent to the children and handling it accordingly. In this example, we will build a React application which takes the state ...
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › how-to-set-parent-state-from-children-component-in-reactjs
How to set Parent State from Children Component in ReactJS? - GeeksforGeeks
July 23, 2025 - To set parent state from child component in React, we will define a callback function in the parent component to update its state. Pass the callback function to the child as a prop.
🌐
CodeSandbox
codesandbox.io › s › react-changing-state-of-child-component-from-parent-4r16r1oxj4
React: Changing state of child component from parent - CodeSandbox
January 26, 2022 - React: Changing state of child component from parent by johnythomas using react, react-dom, react-scripts
Published   Nov 05, 2018
Author   johnythomas
🌐
freeCodeCamp
freecodecamp.org › news › react-changing-state-of-child-component-from-parent-8ab547436271
How to change the state of a child component from its parent in React
November 5, 2018 - Here we have created a ref using React.createRef() method and attached the ref to the Superhero component using the ref attribute. Now we will be able to refer the Superhero node using this.superheroElement.current. We will also be able to call the changeName() function in the Superhero component using this.superheroElement.current.changeName(). Let’s update our handleClick() function in our App component to call the changeName() function.
🌐
Medium
medium.com › geekculture › update-parent-state-from-child-component-with-react-context-api-a56cf3742428
Update state from child to parent with React Context
May 14, 2023 - Normally we pass an event from the parent to the child component, the child component receives the event, and when the event (method) is called with parameters, the method defined in the parent component is triggered and the state is then updated.
🌐
ReScript Forum
forum.rescript-lang.org › t › how-to-update-parent-state-on-updating-parent-state › 4372
How to update parent state on updating parent state? - ReScript Forum
April 4, 2023 - If the parent component state updates, I am passing the updated state to the child component as props, and trigger a re-render of child component. If the onclick function trigger in child component then parent state should be updated.
🌐
GyanBlog
gyanblog.com › homepage › how to update child component state from parent component
How to Update Child Component State from Parent Component | GyanBlog
May 8, 2021 - The solution is to maintain state in parent component, and pass the props to child component. And the child component, will read data from props. import apiClient from '../../components/api/api_client' import SimpleLayout from '../../compon...