Hooks?
Closed this issue ยท 8 comments
Do you plan including hooks "a la react-router" or in some other form?
No plan currently, haven't used them myself
Open to a PR implementing something like this?
- Adds
onEnter(nextLocation)
andonLeave()
attributesonChange(โฆ)
could come later but I'd rather start smallish
- Functions can be synchronous or asynchronous (promise)
- Hooks delay rendering
Possibly, I haven't found any cases where you'd really need it what are you using them for? Maybe I'm doing something weird haha
There are two main use cases:
- Checking credentials (you will then not call the callback or not return a promise, or a rejected one, and handle redirection in hook)
- Fetching data (in replacement of component lifecycle method)
@tj where are you handling authentication for a route then? component life cycles?
ahh yep I've been just using lifecycle methods for both in little wrapper components like component={authenticated(Dashboard)}
. Hooks sound fine but seems easy enough to leave them out as well. I'm mostly ๐ I think since it lets you go more stateless.
I'd also consider just doing something like:
<Authenticated no={this.redirect} yes={this.render} />
in the container(s)
+1!
kinda like delegating this, closing for now