如何更新在“ react-router-dom”的路径上呈现的组件?

问题描述 投票:0回答:1

当我的应用程序运行componentDidMount()时,我获取数据

async componentDidMount() {
  try {
    let players = await playersDAO.read();
    this.setState({ players: players });
  } catch (e) {
    console.log(e);
  }
}

然后将其显示在由react-router-dom由Route渲染的组件上>

<BrowserRouter>
  <Switch>
    <Route
      key="players"
      path="/players"
      render={() => <Players rows={this.state.players} />}
    />
  </Switch>
</BrowserRouter>

我不知道为什么,但是在获取数据时,组件不会更新。也许(很有可能)我做错了什么,但是有人可以帮助我吗?

主题外:我使用Route的渲染专有性,因为我需要为我的组件传递道具,有人知道这样做的更好方法吗?

[当我的应用程序运行componentDidMount()时,我会异步获取数据componentDidMount(){试试{ this.setState({玩家:玩家}); }抓住(e){...

javascript reactjs react-router react-router-dom
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.