onRoute hooks?
See original GitHub issueI’m facing a problem where I need to fetch data when I enter different routes
Here’s an example with just a single view that needs to fetch data. In reality I will have multiple views, and model.items
will change on different views.
I’m not sure how to achieve this functionality without onRoute hooks.
const { h, app } = hyperapp
/** @jsx h */
app({
model: {
items: []
},
reducers: {
updateItems: (model, data) => ({
items: data
})
},
effects: {
fetch: (model, actions) => {
setTimeout(function () {
actions.updateItems([1, 2, 3])
},0)
}
},
view: (model, actions) => {
/* I need to asynchronously fetch items only one time when I enter routes.
If I call an effect here in the view, it will rerender infinitely
since reducers update the model and cause views to render
*/
actions.fetch()
console.log('this is logged on every render')
return (
<div>{model.items}</div>
)
}
})
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Hooks - Fastify
Application Hooks. onReady; onClose; onRoute; onRegister. Scope; Route level hooks; Using Hooks to Inject Custom Properties; Diagnostics Channel Hooks.
Read more >onRoute hook doesn't receive the resolved schema #2123
I don't understand: from my point of view, the hook onRoute is fired with the route configuration with the resolved schema.
Read more >Hooks - Fiber
OnRoute is a hook to execute user functions on each route registeration. Also you can get route properties by route parameter.
Read more >useHistory hook - React Router: Declarative Routing for React.js
The useLocation hook returns the location object that represents the current URL. You can think about it like a useState that returns a...
Read more >The Hooks of React Router - CSS-Tricks
React Router 5 embraces the power of hooks and has introduced four different hooks to help with routing. You will find this article...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Everything is cleared up, thanks!
@traducer