irychen / keepalive-for-react

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

refactor: Allow cache deletion to be handled #16

Closed j-sakamoto closed 1 month ago

j-sakamoto commented 1 month ago

In situations where we wanted to delete the cache and then transition to a new page, I faced the problem that the page to be transitioned to would be blank if the cache was asynchronously removed.

  const navigate = useNavigate()
  const onClickLogo = useCallback(async (e: React.MouseEvent) => {
    e.preventDefault()
    // If the await is removed, a blank component is displayed.
    await aliveRef.current?.removeCache('/') 
    navigate('/')
  }, [navigate, aliveRef])

I created a PR because i think some users may face similar problems.