Javascript Redux toolkit从thunk访问状态

Javascript Redux toolkit从thunk访问状态,javascript,reactjs,redux-toolkit,Javascript,Reactjs,Redux Toolkit,我想在thunk中获取一个存储在state中的值,在本例中是projectId。调用操作时,是否可以访问此值而不将其作为参数传递 interface RepoDetailsState { openIssuesCount: number error: string | null } const initialState: RepoDetailsState = { openIssuesCount: -1, error: null, projectId:

我想在thunk中获取一个存储在state中的值,在本例中是
projectId
。调用操作时,是否可以访问此值而不将其作为参数传递

interface RepoDetailsState {
      openIssuesCount: number
      error: string | null
    }

const initialState: RepoDetailsState = {
  openIssuesCount: -1,
  error: null,
  projectId: 'someProjectId'

}

const repoDetails = createSlice({
  name: 'repoDetails',
  initialState,
  reducers: {
  // ... reducers ...
  }
})

export const {
  getRepoDetailsSuccess,
  getRepoDetailsFailed
} = repoDetails.actions

export default repoDetails.reducer

export const fetchIssuesCount = (
  org: string,
  repo: string
): AppThunk => async dispatch => {
 //How do I access projectId from state?
}

您可以通过
getState
参数访问您的状态

export const fetchIssuesCount = (
  org: string,
  repo: string
): AppThunk => async (dispatch, getState) => {
// Do something with state
 getState()
}

也可以看到。(Ctrl+F getState查看更多示例)

您可以通过
getState
参数访问您的状态

export const fetchIssuesCount = (
  org: string,
  repo: string
): AppThunk => async (dispatch, getState) => {
// Do something with state
 getState()
}
也可以看到。(Ctrl+F getState可查看更多示例)