Skip to content

cqq151314/react-practice

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-practice

自己玩

  • npm install

  • npm run dev

  • 访问 http://localhost:8080/src/index.html

练习内容

乱七八糟

  • 关于 React 在 0.13 中取消自动绑定的原因:
    • 表面上看自动绑定给开发带来了便利,而Facebook却认为这破坏了JavaScript的语言习惯,其背后的神奇(Magic)逻辑或许会给初学者带来困惑,甚至开发者如果从React再转到其它库也可能会无所适从。
  • 关于 React 对文本加 react-text 注释(comments) 的原因:
    • 该注释是提供为 React 内部使用的, 举例说明 如果你需要 render 两个彼此相邻的变量, React 通过这些注释区别两个变量的位置, 从而进行准确的更新, 之前版本使用的使用 <span>
  • 关于 React render 只能输出 0 个 或 1 个节点, 会导致添加不必要的包裹节点: 未来版本可能会支持多节点输出
  • State 应该放什么? 引用别人一段:
function shouldIKeepSomethingInReactState() {
    if (canICalculateItFromProps()) {
        // Don't duplicate data from props in state
        // Calculate what you can in render() method.
        return false;
    }

    if (!amIUsingItInRenderMethod()) {
        // Don't keep something in the state
        // if you don't use it for rendering.
        // For example, API subscriptions are
        // better off as custom private fields
        // or variables in external modules.
    }

    // you can use React state for this.
    return true
}
  • 关于 PropTypes
    • 复杂类型 使用 shape
    • 自定义校验
    • 生产环境, 删除 PropTypes: 插件
    • 通过 PropTypes 生成 doc: docgen
  • React StoryBook (?)
  • Container and Presentational pattern example
    • Container components
      • They are more concerned about the behavior
      • They render their presentational components
      • They make API calls and manipulate data
      • They define event handlers
      • They are written as classes
    • Presentational components
      • They are more concerned with visual representation
      • They render the HTML markup(or other components)
      • They receive data from the parents in the form of props
      • They are often written as stateless functional components
  • Mixin and HoC (代码复用的角度, React 引入了 Mixin, 但又在 0.13 取消了 Mixin, 原因如下: 见官网)
    • 官方提到的三个原因: 1. 引入了隐式依赖 2. 命名冲突 3. snowballing complexity
    • 本人认为主要还是命名冲突, 在中小型项目中, 解决了命名冲突, Mixin 也是不错的解决方案, 之前在 AngularJS + ES6 中使用 Mixin 装饰器的尝试, 效果还是很不错的.
    • HoC
      • 扩展 prop
      • 将无状态组件扩展为有状态组件
      • 其它功能 (?)

相关书籍

补充

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 84.4%
  • CSS 14.7%
  • HTML 0.9%