Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
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; -
@shellbug I do it in render function, how can I make it for the entire component to access?
-
@gitpush that would be nice but you can't. I do it as the first statement of each method (when needed).
-
@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? -
@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. -
@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 -
@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. -
@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
Related Rants
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 :)
undefined
i still have hope (lol)
i want a break
state
reactjs
me tired