[关闭]
@2890594972 2019-05-17T07:16:49.000000Z 字数 1633 阅读 1542

02 | 以组件方式考虑UI的构建

react入门到精通 react


案例1:以组件思想构建页面

image_1db27fkpm18ha172914381rgsphf9.png-164.6kB

如何理解组件

  1. 组件状态有两种:
  2. 注意:props用来传值, state用来维护数据

image_1db27jqrceg915fp1nb3muctkfp.png-110.5kB

创建一个简单的组件

image_1db2ace6t16lf1del1k41lf11r3o16.png-97.2kB

React快捷键

  1. Snippets
  2. Below is a list of all available snippets and the triggers of each one. The ⇥ means the TAB key.
  3. Trigger Content
  4. rcc→ class component skeleton
  5. rrc→ class component skeleton with react-redux connect
  6. rrdc→ class component skeleton with react-redux connect and dispatch
  7. rccp→ class component skeleton with prop types after the class
  8. rcjc→ class component skeleton without import and default export lines
  9. rcfc→ class component skeleton that contains all the lifecycle methods
  10. rwwd→ class component without import statements
  11. rpc→ class pure component skeleton with prop types after the class
  12. rsc→ stateless component skeleton
  13. rscp→ stateless component with prop types skeleton
  14. rsf→ stateless named function skeleton
  15. rsfp→ stateless named function with prop types skeleton
  16. rsi→ stateless component with prop types and implicit return
  17. fcc→ class component with flow types skeleton
  18. fsf→ stateless named function skeleton with flow types skeleton
  19. fsc→ stateless component with flow types skeleton
  20. rpt→ empty propTypes declaration
  21. rdp→ empty defaultProps declaration
  22. con→ class default constructor with props
  23. conc→ class default constructor with props and context
  24. est→ empty state object
  25. cwm→ componentWillMount method
  26. cdm→ componentDidMount method
  27. cwr→ componentWillReceiveProps method
  28. scu→ shouldComponentUpdate method
  29. cwup→ componentWillUpdate method
  30. cdup→ componentDidUpdate method
  31. cwun→ componentWillUnmount method
  32. gsbu→ getSnapshotBeforeUpdate method
  33. gdsfp→ static getDerivedStateFromProps method
  34. cdc→ componentDidCatch method
  35. ren→ render method
  36. sst→ this.setState with object as parameter
  37. ssf→ this.setState with function as parameter
  38. props→ this.props
  39. state→ this.state
  40. bnd→ binds the this of method inside the constructor
  41. disp→ MapDispatchToProps redux function
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注