我在react项目中使用redux forms,这是一个已经初始化了redux forms的应用程序组件。
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严格模式。
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。