12
gitpush
6y

I was wondering why every time my my code is accessing the !valid() part to later realize I was coming back to it = its state is reset = I need a break T_T

P.S. if you find anything in my code make sure to let me know :)

Comments
  • 3
    1: "props.appState" smells bad...

    2: You can use de-structuring to reduce line length and repetition of "this.props", like this:

    const {
    appState,
    fetchProjects,
    redirectToLogin
    } = this.props;
  • 1
    @shellbug I do it in render function, how can I make it for the entire component to access?
  • 2
    @gitpush that would be nice but you can't. I do it as the first statement of each method (when needed).
  • 1
    @shellbug I see, thank you so much man I'll do on fixing that today since my project is still in its early days.

    As you may have noticed i have a "redierctToLogin" I recently found out that react-router has an onEnter, do I move login check to onEnter or keep it per component?
  • 1
    @gitpush thanks to the new notif filter I found out I missed this reply. 😅

    Well, I prefer to have redirects on the componentDidMount of my route components. This feels more react-y and is usually easier to understand/find later on.
  • 2
    @shellbug hahaha no worries man better arrive late than never :p

    As for the redirect thing, I too prefer it that way but the thing is it is a general redirect so basically doing it in componentWillMount is causing repetition in my code
  • 1
    @gitpush I see. In that case this is a good usage for onEnter. You can have a list of private routes and use onEnter to check those and redirect to login.
    Still, you could still do this on a component dedicated to only doing this, and you'll probably need to if you are using react-redux.
  • 2
    @shellbug I am using react-redux, and I like the idea of a dedicated component, I could pass the new URL in the route state. I'm gonna try this, thanks man :D
  • 1
    @gitpush no problem 😉
Add Comment