每个人都快乐的周末!我从早上起就搞不好意思 . 我试图找出如何让页面留在页面上,但让问题和响应选择动态 . 在下一个人按下之后,选择将被存储到json数据中 . 任何人都可以帮助我,我会非常感激 . 请参阅下面的代码和图片!谢谢!
import React, { Component } from "react";
import { Button } from "reactstrap";
return (
<div>
<div className="howMuchText">How much does it cost to build an app</div>
<div>
<l1>{this.state.form}</l1>
</div>
<div className="nextButton">
<Button>
Next
</Button>
</div>
</div>
);
}
}
export default Questions;
2 回答
您直接通过mutating state(
this.state = ...
)并在渲染阶段进行了大错误 . 你想要实现的目的是初始化状态,你必须在构造函数中执行它 .同样在render方法中,您无法渲染
this.state.form
,因为它是一个对象 . React不允许将对象呈现为子组件的集合 . 您需要为此目的使用数组 .请参考code sandbox .
AppContainer Component
Page Component
Qustions Component
希望这可以帮助
干杯!