Comments (9)
I too am wondering about this. I asked on Stackoverflow.
from suspend-react.
you have clear
, eg: https://github.com/pmndrs/drei/blob/4aa04c93e4e86711f0a5a6777482a92d52988253/src/core/FaceControls.tsx#L350
from suspend-react.
@abernier so is the answer "use an effect"?
from suspend-react.
that's how I did yes -- that way if a dep changes (same as your suspend, in my case videoTextureSrc
), it will be cleaned up and cleared
from suspend-react.
@abernier That's not ideal because it de-couples the effect from it's clean-up.
Suspend-react is aware of when the dependencies change, and so is best-positioned to run clean-up effects at the right time.
from suspend-react.
I thought like you primarily, I even asked about that on Discord
From @drcmda's answer, I guess this decoupling is intentional:
suspense is a cache, unmount means nothing to a cached entry, it will continue to be available
which makes sense to me, it's a cache, nothing more
If you want more, like a side-effect when your cache-key changes, then you have useEffect
from suspend-react.
I see.
Sounds like we should be wrapping suspend in our own hook.
Something like this.
const useSuspense(cb, deps) {
const { value, cleanup } = suspend(cb)
useEffect(() => {
() => cleanup()
}, deps)
return value;
}
...but then we get the pitfall from a lack of reference-counting if two components use the same suspended keys.
useEffect(() => {
() => {
if (lastRef) evictFromCache();
cleanup()
}
}, deps)
Makes me think suspend-react should be providing this.
from suspend-react.
Related Issues (14)
- Cancellation HOT 11
- Re-rendering on clear HOT 2
- Contribution Guide HOT 1
- Wrong file ending. HOT 1
- PeerDependencies complaint under React 16.14
- shallowEqualArrays falling short when using empty array as key
- TypeScript Improvements HOT 6
- Source of 0.0.10 HOT 1
- Assets are not cached correctly using array as useLoader input
- Discussion: Concerns about uncollectable references? HOT 2
- Suggestion: Document ways to avoid key collisions HOT 3
- Fallback to previous render HOT 1
- How would you use suspend-react when fetching through a hook? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from suspend-react.