tj/react-enroute

Hooks?

Closed this issue ยท 8 comments

Do you plan including hooks "a la react-router" or in some other form?

tj commented

No plan currently, haven't used them myself

Open to a PR implementing something like this?

  • Adds onEnter(nextLocation) and onLeave() attributes
  • Functions can be synchronous or asynchronous (promise)
  • Hooks delay rendering
tj commented

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?

tj commented

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!

tj commented

kinda like delegating this, closing for now