gpt4 book ai didi

reactjs - 如何修复 `Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code.` ?

转载 作者:行者123 更新时间:2023-12-04 12:35:36 24 4
gpt4 key购买 nike

我在 react 项目中使用 redux 表单,这是具有 redux 表单初始化的应用程序组件:

import { Field, reduxForm } from 'redux-form';

const onSubmit = (values) => {
alert(JSON.stringify(values));
};
function App(props) {
return (
<div className="App">
<form onSubmit={props.handleSubmit}>
<div>
<label htmlFor="firstName">First Name</label>
<Field name="firstName" component="input" type="text" />
</div>
<div>
<label htmlFor="lastName">Last Name</label>
<Field name="lastName" component="input" type="text" />
</div>
<div>
<label htmlFor="email">Email</label>
<Field name="email" component="input" type="email" />
</div>
<button type="submit">Submit</button>
</form>
{props.number}
<button onClick={() => props.callAction()} />
</div>
);
}


App = reduxForm({
form: 'contact',
onSubmit
})(App);


但是我在控制台中收到此错误,该错误来自 react strict 模式:
 Using UNSAFE_componentWillReceiveProps in strict mode is not recommended and may indicate bugs in your code.
* Move data fetching code or side effects to componentDidUpdate.
* If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at:state

Please update the following components: Field, Form(App)

我该如何解决这个错误?

最佳答案

这似乎是一个悬而未决的问题。您应该等待 redux-form 的作者发布更新或寻找替代库(因为这个库的作者似乎说在大多数情况下您不应该使用它)– apokryfos

关于reactjs - 如何修复 `Using UNSAFE_componentWillMount in strict mode is not recommended and may indicate bugs in your code.` ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62202890/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com