简体   繁体   English

如何在React Native中在Drawer Navigator中动态添加项目?

[英]How to dynamically add items in Drawer Navigator in react native?

I wan to add Routes into my drawer navigator from an api respones. 我想从api响应中将Routes添加到我的抽屉导航器中。 It looks like this : 看起来像这样:

componentDidMount() {
    let steps = [
        { 
            "commonName" : "Input Configuration",
            "compname" : "InputConfig"
        },
        {
            "commonName" : "Dashboard",
            "compname" : "Dashboard"
        }
    ]

Where commonName is the name of the route and compname is the name of corresponding component name. 其中commonName是路由的名称,compname是相应组件名称的名称。 How to add these items into Drawer Navigator? 如何将这些项目添加到Drawer Navigator中?

I would keep steps as an initial state variable, and as API responses come in, call this.setState(change steps here) . 我会将steps保留为初始状态变量,随着API响应的出现,调用this.setState(change steps here) It's a little difficult to say how exactly to implement that without more information on where your API calls are happening and if you're receiving the data in the same class, but that is the general process. 如果没有更多有关API调用发生的位置以及您是否要接收同一类中的数据的信息,很难说出如何准确地实现这一点有点困难,但这是常规过程。 Set the state, and set up your component to use that state, and as the state needs to change, call setState . 设置状态,并设置组件以使用该状态,并在需要更改状态时调用setState

If you are using redux its a little easier. 如果您正在使用redux,它会容易一些。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM