简体   繁体   English

如何在 React Native 中创建基于无限问题的应用程序

[英]How to create infinite questions based app in React Native

So I am building an app where I need to ask user unknown amount of questions, it can be 5 or it can be 50, it wouldn't make sense to make 50 screens.所以我正在构建一个应用程序,我需要问用户未知数量的问题,可以是 5 个,也可以是 50 个,制作 50 个屏幕是没有意义的。 I have 4 types of questions and that would be 4 components.我有 4 种类型的问题,这将是 4 个组成部分。 And I want to keep all 5-... question on single screen, but they need to change when I press "NEXT".而且我想在单个屏幕上保留所有 5-... 问题,但是当我按“NEXT”时它们需要更改。 Is that good aproach at all, and how to do that?这是一个很好的方法吗,如何做到这一点? Just explanation you don't have to bother with writing all the code.只是解释您不必费心编写所有代码。 And if there is any other aproach to that?如果有任何其他方法呢?

If you need any more info please comment.如果您需要更多信息,请发表评论。

Thank you!谢谢!

You could make a conditional render.您可以进行条件渲染。 Depending on your state value, return a different component to render and every time you press next update your state.根据您的状态值,返回不同的组件进行渲染,并且每次按下 next 更新您的状态。 This way you wont need to change screens.这样你就不需要换屏幕了。

render () {
 swtich(this.state.questionType) {
    case 1: return <Quest01 />
    case 2: return <Quest02 />
    .
    .
    .
  }
}

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

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