React Redux Tutorials - 5 - Actions


Actions

  • The only way your application can interact with the store.
  • Carry some information from your app to the redux store.
  • Plain JavaScript objects.
  • Have a type property that indicates the type of action being performed.
  • The type property is typically defined as a string constants.
  • // (1) define a string constant(to avoid spelling mistake)
    const BUY_CAKE = 'BUY_CAKE' 
    
    // (2) define an action
    // action 객체의 형태적 제한사항은 type 프로퍼티를 가져야한다는 것 외에는 없다.
    {
      type: BUY_CAKE,
      info: 'first redux action'
    }
    
    // (3) implement an action creator(function that returns an action) - replaces step (2)
    function buyCake() {
      return {
        type: BUY_CAKE,
        info: 'first redux action'
      }
    }
    なぜaction creatorの形式で書くのですか?
    🔗 Why action creators?