Advertisement
Guest User

Redux questions.

a guest
May 4th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Question how do I get the responseText back on my loginReducer?
  2. //Code below is working on the example, just some snippets, I think im close to understanding but not completely.
  3.  
  4. //Actions:
  5.         fetch('https://google.com')
  6.             .then((response) => response.text())
  7.             .then((responseText) => {
  8.                 console.log(responseText);
  9.             dispatch(actionsCreators.succesLogin(responseText));
  10.  
  11. //Const actionsCreators
  12. //how does 'data' or any other type of variable work here? related to reducers or
  13.     succesLogin: (data: Object): Object => ({
  14.         type: actionsTypes.SUCCES_ON_LOGIN,
  15.         data
  16.     }),
  17.  
  18. //Initial State
  19. //Should data be part of initial state?
  20. const initialState = {
  21.     isLoggedIn: false,
  22.     waitingSymbol: false,
  23.     error: ""
  24. };
  25.  
  26. //loginReducer:
  27. //how to get the passed back variables here?
  28. const loginReducer = ( state = initialState, action ) => {
  29.     switch (action.type) {
  30.         case types.SUCCES_ON_LOGIN:
  31.             return Object.assign({}, state, {
  32.                 isLoggedIn: true,
  33.                 waitingSymbol: true,
  34.                 error: "Login success"
  35.             });
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement