因此,我试图将redux与reactjs连接起来,以存储有关单击的组件的一些信息。单击某个组件后,redux存储被更新,我希望它在呈现下一页之前检查存储。我可以确认状态已用数据更新,但是当我使用mapStateToProps时,状态是调度功能而不是数据?
ConnectedRequestInformation.js容器
import { connect } from "react-redux";
import requestInformationComponent from "../components/pages/pipeline/requestInformation";
const mapStateToProps = (state) => {
console.log(state)
return {typeOfRequest: state.typeOfRequest}
}
export default connect(
() => ({}),
mapStateToProps
)(requestInformationComponent);
RequestInformationComponent
import React from "react";
import { Container, Header } from "semantic-ui-react";
import DynamicFormComponent from "../../helpers/DynamicForm"
export const requestInformation = (typeOfRequest) => (
<div>
<DynamicFormComponent requestType={typeOfRequest}/>
</div>
);
export default requestInformation
容器中的控制台日志会打印出来。
function dispatch(action) {
if (!isPlainObject(action)) {
throw new Error('Actions must be plain objects. ' + 'Use custom middleware for async actions.');
}
if (typeof action.type === 'undefined') {
throw new Error('Actions may not have an undefined "type" property. ' + 'Have y
ou misspelled a constant?');
}
if (isDispatching) {
throw new Error('Reducers may not dispatch actions.');
}
try {
isDispatching = true;
currentState = currentReducer(currentState, action);
} finally {
isDispatching = false;
}
var listeners = currentListeners = nextListeners;
for (var i = 0; i < listeners.length; i++) {
var listener = listeners[i];
listener();
}
return action;
}
答案 0 :(得分:0)
您的以下代码:
export default connect(
() => ({}),
mapStateToProps
)(requestInformationComponent);
应该是
export default connect(mapStateToProps)(requestInformationComponent);
因此mapStateToProps
应该是connect函数的第一个参数。