0

I'm trying to change the state title value to the value I give in the router, but I do not know why it does not work. This code is compiled, but the title is an empty string all the time. How Can I write a code?

class Header extends React.Component {
  state = {
    title: '',
  };

  updateTitle(title) {
    this.setState({ title });
  }

 render() {
    const { title } = this.state;

    return (
          <Typography>
              {title}
            </Typography>

<Switch>
            <Route
              exact
              path="/"
              render={() => (<DashboardPage updateTitle={this.updateTitle} />)}
              title="Dashboard"
            />

            <Route
              path="/payment"
              render={() => (<PaymentPage updateTitle={this.updateTitle} />)}
              title="Payment"
            />

          </Switch>
)};
rayman22
  • 81
  • 10

0 Answers0