score:0

as in react, the data flows down, for the child component to change state of its parent, it can only be done via callback passed the parent.

you can pass the callback via props, context api, or use any state management library.

for example:

class app extends component {
  state = { show: "login", user: "guest" };

  render() {
    return (
      <>
        <menu />
        <activities onclick={this.setstate} />
      </>
    );
  }
}

class app extends component {
  state = { show: "login", user: "guest" };

  render() {
    return (
      <ul>
        <li onclick={() => this.props.onclick({ show: "home" })}>
          <a>home</a>
        </li>
        <li onclick={() => this.props.onclick({ show: "activities" })}>
          <a>activities</a>
        </li>
      </ul>
    );
  }
}

Related Query

More Query from same tag