Access Redux store in JavaScript function

后端 未结 2 500
我寻月下人不归
我寻月下人不归 2021-02-08 09:38

Is it possible to map redux state to a regular javascript function rather than a React component?

If not, is there another way for connecting redux state to a function?

2条回答
  •  迷失自我
    2021-02-08 10:10

    Suppose you have an action. Just add some marker - and the reducer will detect whether skip that or not:

    Action:
    {
      type: 'SOMETYPE',
      paylod: data,
      shouldSkip: true
    }
    
    Reducer:
    export default function ( state = {}, action ) {
      if(action.shouldSkip)
        return state
      switch ( action.type ) {
        case "OTHER_TYPE":
          return action.payload;
        default:
          return state;
      }
    }
    

提交回复
热议问题