Closed ali-garajian closed 3 years ago
v1.11.0 lifecycle hooks supports multiple handlers
import { useDidCache, useDidRecover } from 'react-router-cache-route'
export default function List() {
useDidCache(() => {
console.log('List cached 1')
})
// support multiple effect
useDidCache(() => {
console.log('List cached 2')
})
useDidRecover(() => {
console.log('List recovered')
})
return (
// ...
)
}
Right now with the methods "didCache" and "didRecover", one could only add one callback for each life cycle. In my case, I'm using these methods in multiple custom hooks, and each of them needs to add its own callback. But since that's not possible, I have to lift the logic up to the their parent and expose callbacks from my hooks and call them all at one place, which kinda leads to smelly and duplicate code! It would have been great if something like "didCache.addListener(() => {})" was possbile.