Redux-Saga观察者操作被调用两次

时间:2019-01-18 12:02:23

标签: javascript reactjs redux react-redux redux-saga

我通过以下方式进行了英雄传奇设置。

export function* watchInstanceDataSetAssocSaga() {
  yield takeLatest(
    actionTypes.FETCH_INSTANCE_DATASETS_ASSOC_INITIATE,
    fetchInstanceDataSetAssocSaga
  )
}

const actionWatchers = sagaMiddleware => {
  sagaMiddleware.run(watchInstanceDataSetAssocSaga)
}


function* fetchInstanceDataSetAssocSaga(action) {
  console.log('in saga')
 //Making Api Call
}

const composeEnhancers =
  process.env.NODE_ENV === 'development'
    ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
    : null || compose
const sagaMiddleware = createSagaMiddleware()
const store = createStore(
  rootReducer,
  composeEnhancers(applyMiddleware(sagaMiddleware))
)
actionWatchers(sagaMiddleware)

在我的容器组件中,我正在分派动作来调用传奇。

export class InstanceDatasetsAssoc extends Component {
  componentWillMount() {
    console.log('in componentWillMount')
  }
  componentDidMount() {
    if (!this.props.records.length) {
      console.log('in did mount')
      const {
        pageInfo: {
          first: { url }
        }
      } = this.props
      let paginationParams = {
        url
      }
      this.props.onFetchInstanceDataSetAssoc(paginationParams)
    }
  }
  ...
}

当我点击url时,我得到以下日志语句。

**

  in componentWillMount
  in saga
  in did mount
  in saga

**

我的传奇被两次调用,就像我被两次“ in saga”调用一样,因此我的api调用发生了两次。

有人可以解释我想念的是什么吗?

0 个答案:

没有答案