You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
闭包陷阱
这这两段代码
console.log
会有差异。因为这两个值是不一样的,那个引用第一个引用是第一个引用是上一次更新的值,然后你下面的是直接位出来的是是一个新的对象,所以拿到的是新的值。
两个是不一样的对象,但要用第一种的话,渲染到页面上会自动渲染。
如果直接打印出来则是上一次的值。
react是声明式的,自动帮你更新页面渲染的,所以它会区分这次更新跟下次更新的区别,就就是跟其他的框架不一样的地方。
Beta Was this translation helpful? Give feedback.
All reactions