Open peterbe opened 7 years ago
By the way, here's why I think it's an awesome idea.
I have a tabular page. It does an AJAX query (e.g. /api/items/?page=1
). If you click on one of them, it goes to the "perma page" for that item. Then, to get the data it does an AJAX query again (e.g. /api/items?id=1234
and something like...
.then(result => {
store.app.item = result.items[0]
})
(It also loads other stuff that isn't displayed in the tabular page)
So by intercepting the click, from the tabular page, I can do this:
<InterceptableLink
view={views.podcast}
params={{id: podcast.id, slug: podcast.slug}}
store={store}
onClick={e => {
store.app.podcast = podcast // <--- here lies the magic!
}}
>
<img src={imageURL} role="presentation" className="rounded"/>
</InterceptableLink>
That means that when the perma page loads, the data will already have been put in the store and thus it loads instantaneous!
Ah, this looks really interesting. Will take a stab at it soon! 🙌
I use the
Link
component and it's awesome. But there's no way I can intercept that click. In particular, depending on some programmatic logic I'd like to do some things in theonClick
that may or may not cancel the click. For example:It's always a bit weird to have multiple
onClick
events because it's confusing what the order is supposed to be.Here's a hack I wrote for my own needs. This works well:
Do you think that's a good idea? If so, I can clean it up in the form of a PR.