删除了带有Ref的错误.若要访问包装的实例,请在使用Redux Form时对连接的组件使用ref



我第一次尝试让Redux Form工作,但我收到了以下错误:

Ref的不变冲突被删除。访问包装的例如,在连接的组件上使用ref。

我做错了什么?一旦我写入(从示例中复制/粘贴(存储,就会抛出错误。

这是代码。

import React from "react";
import ReactDOM from "react-dom";
import { createStore, combineReducers } from 'redux'
import { reducer as formReducer } from 'redux-form'
const rootReducer = combineReducers({
form: formReducer
})
const store = createStore(rootReducer);

function App() {
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

我还制作了一个代码沙盒来显示这个问题:https://codesandbox.io/s/07xzolv60

只需更新到redux表单的最新版本(8.1.0(。无需降级。

我也遇到了同样的问题,显然redux形式react redux版本大于6时还不能很好地工作。

对我来说,有帮助的是将react redu包降级到版本5:

npm install react-redux@5.1.1 --save

虽然上述方法确实有效,但如果您想使用最新的,您所需要做的就是将类组件重构为函数组件。查找withRef()API。(请投票支持这一正确答案,以帮助其他开发者。(

https://redux-form.com/7.1.2/docs/api/fieldarray.md/#props-您可以将数组代码-传递给代码字段

我不建议降级react-redux,而是说您将两个库都更新到最新版本,问题应该得到解决。请参阅关于从v6迁移到v8的Redux Form文档。

https://redux-form.com/8.2.2/docs/MigrationGuide.md

https://github.com/reduxjs/react-redux/releases/tag/v6.0.0

连接的withRef选项已替换为forwardRef

export default 
connect(
mapStateToProps,
mapDispatchToProps, null, {forwardRef: true})(Component)

最新更新