Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-implement react-keep-alive #38

Open
ShenChang618 opened this issue Sep 4, 2019 · 5 comments
Open

Re-implement react-keep-alive #38

ShenChang618 opened this issue Sep 4, 2019 · 5 comments
Labels
question Further information is requested

Comments

@ShenChang618
Copy link
Member

At present, there are some problems in implementation. The biggest problem is that context can not be easily accessed.

Therefore, I hope to solve this problem through refactoring, I do not know what better ideas you have?

@ShenChang618 ShenChang618 added the question Further information is requested label Sep 4, 2019
@ShenChang618 ShenChang618 pinned this issue Sep 4, 2019
@2788
Copy link

2788 commented Feb 21, 2020

看了在线例子, 好像是在一个专门的地方渲染组件, 然后通过createPortal转移到真实dom上面?
不知道我理解有没有错误,反正能看出来跟逻辑上的组件树会有出入,在keepAlive父级添加click事件,在keepalive上面点击 父级不会响应

@guoyunhe
Copy link

guoyunhe commented Dec 2, 2021

我看很多人遇到了 state 不能和 在同一级用的问题:

export function App() {
  const [value, setValue] = useState('');
  return <KeepAlive>
    <input value={value} setValue={e => setValue(e.target.value)}
  </KeepAlive>
}

我想能不能不用组件的方式提供 keep alive 而是用 HOC,这样就不用担心有人在同一层用 state 和 keep alive 了:

function App() {
  const [value, setValue] = useState('');
  return <input value={value} setValue={e => setValue(e.target.value)}
}

export keepAlive(App);

@guoyunhe
Copy link

希望能够支持手动卸载,以免有些情况下内存消耗太大

@svtkhn
Copy link

svtkhn commented May 11, 2022

Seems like React v18 is planning to finally officially support keep-alive feature. They call it <Offscreen>. Hopefully, it will be released soon enough so we don't have to hack around current React's limitations.

@shenjunru
Copy link

欢迎试用 react-fiber-keep-alive,一个基于 react fiber 的 keep-alive 实现

Give a try react-fiber-keep-alive, the react fiber based keep-alive implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants