Reactjs 反应:如何将我的状态作为道具传递给路由器中的子组件?我尝试使用链接,但这不起作用
//陈述 //我想将我的状态作为道具传递给总组件。 //我无法通过我的州考试Reactjs 反应:如何将我的状态作为道具传递给路由器中的子组件?我尝试使用链接,但这不起作用,reactjs,react-router,Reactjs,React Router,//陈述 //我想将我的状态作为道具传递给总组件。 //我无法通过我的州考试 class Main extends React.Component{ constructor(){ super(); this.state = { dish : Dishes, total :"" } {Link to'/Total/${this.state}} 下单 {this.state.total} ) } } export default Main您的代码无法运行,JSX不正确
class Main extends React.Component{
constructor(){
super();
this.state = {
dish : Dishes,
total :""
}
{Link to'/Total/${this.state}}
下单
{this.state.total}
)
}
}
export default Main您的代码无法运行,JSX不正确,缺少标记,您所引用的组件在您提供的代码中不存在我只是想让您知道我正在尝试执行的操作..无法发布整个代码,因为它不是必需的您想在路由到总组件时将此类的状态作为道具传递给总组件
{Link to '/Total/${this.state}'}
<Button style ={{left:"45%", top:"20px",bottom:"20px"}} size = "Large" variant="contained" color="secondary" onClick={this.handleChange} >Place your Order</Button></Link>
<h1>{this.state.total}</h1>
</div>
</div>
)