我有一个扩展形式的组件,例如:
import React from "react";
import Form from "./common/form";
import AppFeature from "./common/appFeature";
class AddFeature extends Form {
render() {
<AppFeature role={"newRole"} />}
}
当我尝试通过appfeature
获取this.props.role
组件中的角色值时。我会得到undefined
。
任何解决方法?
答案 0 :(得分:0)
您的doSubmit
功能不正确。
您需要将状态更新-将showFeatures
更改为true
,以呈现AddFeature
组件。
您正在呼叫history.push
到一个未定义的特定路由,并使用React Router
来做到这一点。
使用以下代码,您将可以为AddFeature
组件获取道具
doSubmit = async ex => {
try {
this.setState({
showFeatures: true
})
} catch (ex) {
console.log(ex.response);
}
};