Skip to content

Sample State

Kevin Le edited this page Mar 17, 2022 · 32 revisions

State Shape

{
  entities: {
    users: {},
    questions: {},
    answers: {},
    votes: {}
  },
  session: {
    currentUserId: #
  },
  errors: {
    auth: [''],
    questionForm: [''],
  },
  ui: {
    loading: t / f
  }
}

Example State

{
  entities: {
    users: {
      11: {
        id: 11,
        username: "Clone11",
        email: "clone1@kevinle.com"
      },
      22: {
        id: 22,
        username: "Clone22",
        email: "clone2@kevinle.com"
      },
      33: {
        id: 33,
        username: "Clone33",
        email: "clone3@kevinle.com"
      }
    },
    questions: {
      1: {
        id: 1,
        askerId: 11,
        title: "How do I make a website clone?",
        body: "Not sure where to start for a website clone. What does everyone think?",
      },
      2: {
        id: 2,
        askerId: 22,
        title: "Ruby or Javascript as a first language?",
        body: "Hello Stack Overclones. I want to pick up coding. I am reading that it is recommended that 
               I learn Ruby or Javascript as my first language. Which of those two would you recommend?",
      },
      3: {
        id: 3,
        askerId: 33,
        title: "How do I slice into an array in Ruby?",
        body: "I am trying to get the 3rd element in my array: arr = [232, 94, 54]. How do I pull the 3rd 
               data point 54 and save it as a variable?",
      }
    },
    answers: {
      1: {
        id: 1,
        questionId: 1,
        answererId: 22,
        body: "App Academy Open has a great guide on building a website clone."
      },
      2: {
        id: 2,
        questionId: 1,
        answererId: 33,
        body: "Why clone a website? Just make a new billion dollar website from scratch."
      },
      3: {
        id: 3,
        questionId: 3,
        answererId: 11,
        body: "To get the third element, you want to key into the array at index 2 (because Ruby indices 
               start at 0). Then storing it into a variable, you can do third_ele = array[2]."
      }
    },
    votes: {
      1: {
        id: 1,
        voterId: 22,
        questionId: 1,
        isUpvote: false
      },
      2: { 
        id: 2,
        voterId: 11,
        isUpvote: true
      }
    }
  },
  ui: {
     loading: true/false
   },
  errors: {
     auth: ["The email or password is incorrect."],
     questionForm: ["Question body cannot be blank"],
   },
  session: { currentUserId: 11 }
}

Clone this wiki locally