V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
soclearn
V2EX  ›  React

为啥前一个渲染的数据会在后一个渲染的数据到达前,会留下拖影,如何解决

  •  
  •   soclearn ·
    minlearn · Nov 19, 2023 · 1582 views
    This topic created in 899 days ago, the information mentioned may be changed or developed.

    react 同一个组件,渲染来自 redux state 里的不同数据,比如一个文章组件显示 state 不同 post

    为啥前一个渲染的数据会在后一个渲染的数据到达前,会留下拖影,然后才显示后一个渲染数据

    如何在前一个组件的 unmount 里消除掉该份数据,

    这属于啥课题,google “react force clean up state when component unmount” “react dont cleanup effect when unmount” “react dont clean up previous render”

    都找不出答案

    用的 class component,没有使用 use hooks

    第一次用 react ,请大佬赐教

    4 replies    2023-11-20 01:05:17 +08:00
    iOCZS
        1
    iOCZS  
       Nov 19, 2023
    talk is cheap, show me the code
    sillydaddy
        2
    sillydaddy  
       Nov 19, 2023
    贴一下关键代码吧
    debuggerx
        3
    debuggerx  
       Nov 19, 2023 via Android   ❤️ 1
    加 loading 组件来控制啊
    soclearn
        4
    soclearn  
    OP
       Nov 20, 2023
    @debuggerx

    render()
    前面有简单的 if (!post) { return <div>loading...</div> }
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   6290 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 52ms · UTC 02:47 · PVG 10:47 · LAX 19:47 · JFK 22:47
    ♥ Do have faith in what you're doing.