为什么我的组件没有渲染?
import React, { Component } from 'react';
import {Chokers, Bracelets, FRings, MRings} from './AllItems.js'
class App extends Component {
handleClick(e){
<Chokers chokers={this.props.items.Chokers}/>
}
render() {
return (
<div className="App">
<ul style={{display: 'inline'}}>
<li onClick={this.handleClick.bind(this)}>Chokers</li>
<li><a href=""></a><Bracelets bracelets={this.props.items.Bracelets}/>Bracelets</li>
<li><FRings frings={this.props.items.FRings}/>Rings for Women</li>
<li><MRings mrings={this.props.items.MRings}/>Rings for Men</li>
</ul>
</div>
);
}
}
export default App;
基本上我的 this.props.items.Chokers 示例调用了我传递的 json 文件。
我只想在 onClick 事件中创建指向另一个组件的链接。我遇到的问题是我的 handleClick 下的组件没有呈现。
原文由 user3450754 发布,翻译遵循 CC BY-SA 4.0 许可协议
If you want to render
Chockers
component on the click of item, then write it like this, create thestate
variable and set ittrue
onClick
项目:检查
jsfiddle
工作示例: https://jsfiddle.net/ocg4ebdf/