Posts

Showing posts with the label react-router

React authentication flickering issue in changing route

React authentication flickering issue in changing route I'm building several application in react , the last one is a admin panel so my react app must have authentication, absolutely all of my products used Server Side Rendering . react react Server Side Rendering For The last case, back-end team use pass me Token for handling authorization, they technologies are Java , Spring , Redis and etc base. Token Java Spring Redis When I send username and password to their server, If the information be correct, they send for me token and something else, I store it in localStorage and change the root state of react application as login, because of this change app use a different routing . username password token localStorage state react routing Everything looks good but what happen when I refresh the page? here the issue will happen, the login state is false so app goes to login page, in componentDidMount I read the localStorage and find out Oah! I got the token before and th...

“Warning: Can't call setState (or forceUpdate) on an unmounted component” after updating firebase database

“Warning: Can't call setState (or forceUpdate) on an unmounted component” after updating firebase database I'm trying to update some data to my firebase database on form submit, but when I click submit I get the following warning: Warning: Can't call setState (or forceUpdate) on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method. Below is the code that gets executed on submit. If I remove the update code the warning goes away but I need to save the data how can I fix this? handleRewardFormSubmit = event => { event.preventDefault(); const self = this; let points = 0; const memberId = this.state.selectedMember; const groupID = this.state.groupid; const selectedPoints = Number(this.state.selectedPoints); const memberRef = database .ref("members") .child...

React Router + Redux - Dispatch an async action on route change?

React Router + Redux - Dispatch an async action on route change? I have a universal react app that's using redux and react-router. I have several routes as follows: /2016 /2015 /2014 /2013 etc. Each route requires data from an API. Currently, i have the <Link> elements in the Navigation component dispatch an async action onClick , which populates the store with data from the API for that route. <Link> onClick For MVP, i'm just overwriting the post: {} contents in the store with the new post contents when the route changes, that way we get any new content that was on the API. post: {} I've realise that having the action dispatchers on the <Link> buttons isn't optimal, as hitting the back button does not re-trigger the action dispatch to get the content for the previous route. <Link> Is there a way to get React Router to trigger the dispatch action anytime a route change occurs? (Limiting it to listen to a specific set of routes would be a bonus...