irychen / keepalive-for-react

React KeepAlive is a component that can cache the state of the component and reuse it when needed.
MIT License
193 stars 34 forks source link

[Feature Request] Enhance the capabilities of KeepAliveContext #25

Closed condorheroblog closed 1 month ago

condorheroblog commented 1 month ago

The properties and methods on the KeepAliveRef method should also be available on the KeepAliveContext.

The reason for this is that sub components can flexibly read and control the behavior of KeepAlive through the KeepAliveContext.

condorheroblog commented 1 month ago

Please let me explain the benefits of doing this.

For example, if I want to add a cache flag to the tab, I can directly call getCaches through KeepAliveContext in this component.

Some closing operations of the tab can also be easily obtained through KeepAliveContext.

In this way, my tab component does not need to exchange data with the outside world, everything is done internally.

image
irychen commented 1 month ago

It is not necessary to reference https://github.com/irychen/super-admin. Keepalive will automatically manage cached React nodes, so the important thing is to manage the tab's data, which is independent of the Keepalive cached nodes. Even manually removing cached nodes is not necessary

irychen commented 1 month ago

If you believe it is meaningful for your project, you can commit a pull request (PR). There is a good opportunity to refactor the useImperativeHandle code implementation because it contains redundant code in relation to the props of CacheComponent.

irychen commented 1 month ago

If you don't have spare time, perhaps I will add this feature next month