SHARE
TWEET

Untitled

a guest Aug 19th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // App
  2. class App extends React.Component {
  3.   componentDidMount() {
  4.     store.dispatch(loadUser());
  5.   }
  6.  
  7.   render() {
  8.     return (
  9.       <Provider store={store}>
  10.         <div className="App">
  11.           <AppNavbar />
  12.           <Container>
  13.             <ItemModal />
  14.             <ShoppingList />
  15.           </Container>
  16.         </div>
  17.       </Provider>
  18.     );
  19.   }
  20. }
  21.  
  22.  
  23.  
  24. // store
  25. const initialState = {};
  26. const middleware = [thunk];
  27. const store = createStore(
  28.   rootReducer,
  29.   initialState,
  30.   compose(
  31.     applyMiddleware(...middleware),
  32.     window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
  33.   )
  34. );
  35.  
  36.  
  37. // action
  38. export const loadUser = () => (dispatch, getState) => {
  39.   dispatch({ type: USER_LOADING });
  40.  
  41.   axios
  42.     .get("/api/auth/user", tokenConfig)
  43.     .then(res =>
  44.       dispatch({
  45.         type: USER_LOADED,
  46.         payload: res.data
  47.       })
  48.     )
  49.     .catch(err => {
  50.       const { data, status } = err.response;
  51.       dispatch(returnErrors(data, status));
  52.       dispatch({
  53.         type: AUTH_ERROR
  54.       });
  55.     });
  56. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top