Created
          October 7, 2019 12:51 
        
      - 
      
 - 
        
Save jleei/43264905857b72d65df4cb90d40296e4 to your computer and use it in GitHub Desktop.  
Revisions
- 
        
flexdinesh revised this gist
Sep 29, 2019 . 1 changed file with 26 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ import React from 'react'; import PropTypes from 'prop-types'; import { Route, Redirect, } from 'react-router-dom'; const ProtectedRoute = ({ component: Component, ...rest }) => { const { location: { state: { isAuthenticated = false } = {} } = {} } = rest; return ( <Route {...rest} render={(props) => ( isAuthenticated ? (<Component {...props} />) : (<Redirect to="/login" />) )} /> ); }; ProtectedRoute.propTypes = { component: PropTypes.func }; export default ProtectedRoute;  - 
        
flexdinesh revised this gist
Aug 16, 2019 . 1 changed file with 28 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ const MAX_RETRIES = 3; const RETRY_INTERVAL = 3000; const lazy = (pr: Promise<any>): Promise<any> => { const fetchCompomponent = ( promise: Promise<any>, retryCount: number = 0 ): Promise<any> => { return promise.catch(err => { retryCount += 1; if (retryCount <= MAX_RETRIES) { const delayedFetch = new Promise(resolve => { const timeoutId = setTimeout(() => { clearTimeout(timeoutId); resolve(fetchCompomponent(pr, retryCount)); }, RETRY_INTERVAL); }); return delayedFetch; } throw err; }); }; return fetchCompomponent(pr); }; export default lazy;  - 
        
flexdinesh revised this gist
Jul 16, 2019 . 1 changed file with 32 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ import React, { useState } from 'react'; const initialState = { app: { hasLoaded: false } }; const AppContext = React.createContext(initialState); function AppProvider({ children }) { const [app, setAppState] = useState(initialState.app); function setAppStateImmutably(appState) { const prevState = { ...app }; setAppState({ ...prevState, ...appState }); } return ( <AppContext.Provider value={{ app, setAppState: setAppStateImmutably }} > {children} </AppContext.Provider> ); } export default AppProvider; export { AppContext };  - 
        
flexdinesh revised this gist
Mar 29, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ // set state from prev state values this.setState((prevState, props) => ({ counter: prevState.counter + props.increment }));  - 
        
flexdinesh renamed this gist
Mar 29, 2019 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. - 
        
flexdinesh created this gist
Jan 20, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ # set state from prev state values this.setState((prevState, props) => ({ counter: prevState.counter + props.increment }));