We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
class SomeComponent extends React.Component { render() { return ( {/* 在反引号后面的字符串还是标点符号(包括空格)都会照旧在页面上展示出来 */} <pre>{` Hello , World . `}</pre> ) } } ReactDOM.render( <SomeComponent />, document.getElementById('content') )
DOM上显示的效果是:
<pre> Hello , World . </pre>
今天想花一点时间总结下自己学习React的过程中,结合资料悟到的一些道理:
const Stateless = (props) => ( <div>{ this.props.text }</div> ) <Stateless text="Hello World." />
graph LR 父组件State-->子组件Props
graph LR 父组件Methods-->子组件Props
class ParentComponent extends Component { constructor(props) { super(props); this.state = { open: false; } } toggleChildMenu() { this.setState({ open: !this.state.open }); } render() { return ( <div> <button onClick={this.toggleChildMenu.bind(this)}> Toggle Menu from Parent </button> <ChildComponent open={this.state.open} /> </div> ); } } class ChildComponent extends Component { render() { return ( <Drawer open={this.props.open}/> ); } }
// 伪代码 <div onClick={ this.changeState }>{ this.state.text }</div> changeState () { this.setState({ 'text': 'Hello World.' }) }
shoudComponentUpdate(nextProps, nextState) { // 伪代码 return nextPropppps !== this.props; }
通过设置类似上述合适条件,来防止绝大部分的无效重绘。
参考地址
The text was updated successfully, but these errors were encountered:
No branches or pull requests
工作碰到的
在React中使用pre标签
DOM上显示的效果是:
话题
今天想花一点时间总结下自己学习React的过程中,结合资料悟到的一些道理:
3. 父组件使用子组件的方法 (无法做到,因为React是单向数据流,只能由父组件传给子组件):子组件Methods => 父组件
概念
通过设置类似上述合适条件,来防止绝大部分的无效重绘。
关于上面提及到的组件间状态传递,下一篇博文更新。
The text was updated successfully, but these errors were encountered: