GithubHelp home page GithubHelp logo

Comments (3)

otakustay avatar otakustay commented on July 23, 2024

事实上不用immutable的话react的表现是“未知行为”,因为一个组件是否被走到shouldComponentUpdate这一阶段是非常“不显而易见”的,比如你的任意一个父组件的shouldComponentUpdate返回了false,那么你就没机会判断,比如如果用connect和redux store连接后store的这个值没有变,你也没机会判断

因此,在组件的state上不使用immutable几乎可以肯定会遇到各种各样的坑,而我以为这边用immutable应该已经是常识,所以没有写进规范中

在immutable已经是常识的前提下,只会在2种情况下不继承PureComponent

  1. 需要比shallowEqual更高效的shouldComponentUpdate实现,这种情况下一定会实现shouldComponentUpdate所以没关系
  2. render并不是纯函数((state, prop) => vdom),这种组件事实上和不用immutable是一个道理的,应该避免

再综合上面2点,我认为基本上只会在“有自己更高效的shouldComponentUpdate实现”的情况下才会不继承PureComponent,也希望仅在这种情况下出现这种继承关系

from spec.

errorrik avatar errorrik commented on July 23, 2024

基于用immutable的假设下,这是没问题的。但是,我发现貌似很多产品线并未immutable,特别是未进行状态管理的产品,就是挨个挨个的component在写,这种我们是否需要在style guide中考虑

from spec.

otakustay avatar otakustay commented on July 23, 2024

有没有能作为参考的项目让我看一眼,我思考下这里怎么做取舍吧

from spec.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.