Reactjs React-Redux:如何找到在Redux中调用的最后一个操作并再次触发该操作
我有多个地方,单击时会执行不同的操作 我想找到执行的最新操作,然后使用“续订”按钮再次执行它 如何查找最后一个名为的操作? 它一定在redux系统的某个地方。我只需要知道如何找到它 如何查找最后一个名为的操作?它一定在redux系统的某个地方 我不知道任何地方redux保存过去的行动。但是您可以创建一个用于拦截和保存操作的。比如:Reactjs React-Redux:如何找到在Redux中调用的最后一个操作并再次触发该操作,reactjs,redux,react-redux,Reactjs,Redux,React Redux,我有多个地方,单击时会执行不同的操作 我想找到执行的最新操作,然后使用“续订”按钮再次执行它 如何查找最后一个名为的操作? 它一定在redux系统的某个地方。我只需要知道如何找到它 如何查找最后一个名为的操作?它一定在redux系统的某个地方 我不知道任何地方redux保存过去的行动。但是您可以创建一个用于拦截和保存操作的。比如: let lastAction = null; export const getLastAction = () => lastAction; export co
let lastAction = null;
export const getLastAction = () => lastAction;
export const lastActionMiddleware = store => next => action => {
lastAction = action;
return next(action);
}
// In another file, initialize your store with the middleware
// Your code may look different here if you already have middlewares:
import { createStore, applyMiddleware } from 'redux';
import { lastActionMiddleware } from 'whatever/the/path/is';
const store = createStore(
rootReducer,
rootState,
applyMiddleware(lastActionMIddleware)
)
// And in yet another file, you can look up the most recent action
import { getLastAction } from 'whatever/the/path/is';
// ...
componentDidMount() {
const lastAction = getLastAction();
console.log('the last thing dispatched anywhere was:', lastAction)
}
我认为您需要手动维护在状态中调用的最后一个操作。您是指redux devtools还是打算通过编程启动最后一个操作?