banana
banana
楼主很厉害,感谢分享。
Use `window.history.length`
setTimeout/setInterval调用并不是同步setState,也是异步的 在线例子:https://stackblitz.com/edit/react-ts-sqs8mw?file=App.tsx
这段代码里输出的a是0,而不是3. 证明在setimeout里setState也是异步的
> Akarinx 是合成事件,但是里面用的是setTimeout
这个issue之前是没问题的。React18后setState全部都是异步的,所以不需要再分情况讨论,包括原生DOM事件和setTimeout之类的。 另外我觉得讨论这个问题没多大意义,因为setState本身设计出来就是异步的,要同步的访问state就用第二个参数回调访问啊。不然别人设计出第二个参数干嘛。 - 面试应该问:为什么setState是异步的? - 而不是问:什么情况是同步,什么情况是异步? 参考: https://github.com/facebook/react/issues/11527
这个是原生事件的例子: https://stackblitz.com/edit/react-ts-kabj1e?file=index.tsx,App.tsx > @janyin clickHandler 是通过 react 合成事件调用的呀
不仅是最后一页,第一页也是第二页也是。 就是删除数据导致页数变化不会触发onChange事件
I have the same problem too
 here are my solution. Wrapped div the component, and give id to it, pass 'getPopupContainer' props to component