{"id":280269,"date":"2016-11-01T11:55:03","date_gmt":"2016-11-01T08:55:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=280269"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=280269","title":{"rendered":"Redux-form. \u041a\u043e\u0433\u0434\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0444\u043e\u0440\u043c\u0430\u043c\u0438 \u043f\u0440\u043e\u0441\u0442\u043e"},"content":{"rendered":"<p>\u0414\u0443\u043c\u0430\u044e, \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0437\u043d\u0430\u0435\u0442 \u0441\u0445\u0435\u043c\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 redux: <br \/>  view -&gt; action -&gt; middlewares -&gt; reducers -&gt; state -&gt; view<br \/>  \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 <a href=\"https:\/\/habrahabr.ru\/company\/mailru\/blog\/303456\/\">\u0437\u0434\u0435\u0441\u044c<\/a><br \/>  \u0425\u043e\u0447\u0443 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432\u0430\u0448\u0435\u043c\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e \u0442\u043e\u043c\u0443 \u0436\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 \u0434\u043b\u044f \u0444\u043e\u0440\u043c.<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/fe5\/b38\/6c0\/fe5b386c0433052c00b4dd266fbbfe27.jpg\" alt=\"image\"\/><br \/>  <a name=\"habracut\"><\/a><br \/>  <a href=\"http:\/\/redux-form.com\/6.1.1\/docs\/GettingStarted.md\/\">\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f<\/a> \u043d\u0430 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u043c.<br \/>  \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c:  <\/p>\n<pre><code class=\"bash\"> npm install redux-form <\/code><\/pre>\n<p>  \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0432 \u043d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435:  <\/p>\n<pre><code class=\"javascript\">import { createStore, combineReducers } from 'redux' import { reducer as formReducer } from 'redux-form'  const reducers = {   \/\/ \u0432\u0430\u0448\u0438 \u0440\u0435\u0434\u044e\u0441\u0435\u0440\u044b   form: formReducer     \/\/ \u0412 state \u0432\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0444\u043e\u0440\u043c\u044b \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0435 form } const reducer = combineReducers(reducers) const store = createStore(reducer) <\/code><\/pre>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u043e\u0440\u043c\u0443:  <\/p>\n<pre><code class=\"javascript\">import React, { Component } from 'react'; \/\/ \u0431\u0435\u0440\u0435\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u043f\u043e\u043b\u044f (Field) \u0438 \u043f\u0440\u043e\u0432\u0430\u0439\u0434\u0435\u0440 \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u044b (reduxForm) import { Field, reduxForm } from 'redux-form';  class Form extends Component {     render(){         \/\/ \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e handleSubmit \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a         \/\/ reset \u0441\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0434\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439, \u0437\u0430\u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438         \/\/ \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u043e undefined, \u0442\u0430\u043a \u043a\u0430\u043a \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0435 \u0437\u0430\u0434\u0430\u043d\u043e         const {handleSubmit, reset} = this.props;          const submit = (values) =&gt; console.log(values);          return (             &lt;form onSubmit={handleSubmit(submit)}&gt;                 {\/* \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0438\u043c\u044f \u043f\u043e\u043b\u044f, \u0442\u0438\u043f \u0438 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0440\u0430\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043f\u043e\u0437\u0436\u0435*\/}                 &lt;Field name=&quot;title&quot; component=&quot;input&quot; type=&quot;text&quot;\/&gt;                 &lt;Field name=&quot;text&quot; component=&quot;input&quot; type=&quot;text&quot;\/&gt;                 &lt;div&gt;                     &lt;button type=&quot;button&quot; onClick={reset}&gt;\u041e\u0447\u0438\u0441\u0442\u0438\u0442\u044c \u0444\u043e\u0440\u043c\u0443&lt;\/button&gt;                     &lt;button type=&quot;submit&quot;&gt;\u041e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0444\u043e\u0440\u043c\u0443&lt;\/button&gt;                 &lt;\/div&gt;             &lt;\/form&gt;         );     } } Form = reduxForm({     form: 'post', \/\/ \u0438\u043c\u044f \u0444\u043e\u0440\u043c\u044b \u0432 state (state.form.post) })(Form);  export default Form; <\/code><\/pre>\n<p>  \u0420\u0430\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u043a\u0438\u043d\u0443\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0443\u0440\u043e\u0432\u043d\u0435\u043c \u0432\u044b\u0448\u0435:<br \/>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442:  <\/p>\n<pre><code class=\"javascript\">import React, { Component }  from 'react';  import Form from '.\/Form'  class EditPost extends Component{     constructor(props) {         super(props);     }         handleSubmit = (values) =&gt; {         console.log(values);     };     render() {         let {post, dispatch} = this.props;         return (             &lt;div&gt;                 {\/* \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a*\/}                 &lt;Form onSubmit={this.handleSubmit} \/&gt;             &lt;\/div&gt;         );     } } <\/code><\/pre>\n<p>  \u0418 \u0438\u0437\u043c\u0435\u043d\u0438\u043c \u043d\u0430\u0448\u0443 \u0444\u043e\u0440\u043c\u0443:  <\/p>\n<pre><code class=\"javascript\">\/\/ \u043c\u0435\u043d\u044f\u0435\u043c &lt;form onSubmit={handleSubmit(submit)}&gt; \u043d\u0430  &lt;form onSubmit={handleSubmit}&gt; <\/code><\/pre>\n<p>  \u0415\u0441\u043b\u0438 \u043d\u0430\u043c \u043d\u0430\u0434\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043f\u0440\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c actionCreator initialize, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0444\u043e\u0440\u043c\u044b, \u0432\u0442\u043e\u0440\u044b\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e id:  <\/p>\n<pre><code class=\"javascript\">import React, { Component }  from 'react'; \/\/ \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434 import {initialize} from 'redux-form'; import {connect} from 'react-redux';  import Form from '.\/Form'  class EditPost extends Component{     constructor(props) {         super(props);         \/\/ post = {title: &quot; \u0422\u0435\u043a\u0441\u0442 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 &quot;, text: &quot; \u0422\u0435\u043a\u0441\u0442 \u0441\u0442\u0430\u0442\u044c\u0438 &quot;}         let {post, initializePost} = this.props;         \/\/ \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f         initializePost(post);     }         handleSubmit = (values) =&gt; {         console.log(values);     };     render() {         return (             &lt;div&gt;                 &lt;Form onSubmit={this.handleSubmit} \/&gt;             &lt;\/div&gt;         );     } } \/\/ \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u043c \u0432 props \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0444\u043e\u0440\u043c\u044b function mapDispatchToProps(dispatch){     return {         initializePost: function (post){             dispatch(initialize('post', post));         }     } } \/\/ \u043f\u0440\u043e\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u043c \u0432 props \u043e\u0431\u044a\u0435\u043a\u0442 \u0434\u043b\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438 \u0444\u043e\u0440\u043c\u044b function mapStateToProps(state, ownProps){     const id = ownProps.params.id;     return {        post: state.posts[id]     } } export default connect(mapStateToProps, mapDispatchToProps)(EditPost); <\/code><\/pre>\n<p>  \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 action creators \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <a href=\"http:\/\/redux-form.com\/6.1.1\/docs\/api\/ActionCreators.md\/\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u043d\u0430\u0441 \u043d\u0435 \u0443\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u043f\u043e\u043b\u0435, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0432\u0435\u0440\u0441\u0442\u043a\u0438 \u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439:  <\/p>\n<pre><code class=\"javascript\">import React, { Component } from 'react'; import { Field, reduxForm } from 'redux-form';  class Form extends Component {    \/\/ \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u0432\u043e\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e    renderField = ({ input, label, type}) =&gt; (         &lt;div&gt;             &lt;label&gt;{label}&lt;\/label&gt;             &lt;div&gt;                 &lt;input                     {...input} placeholder={label} type={type}\/&gt;             &lt;\/div&gt;         &lt;\/div&gt;     );     render(){         const {handleSubmit, reset} = this.props;          return (             &lt;form onSubmit={handleSubmit}&gt;                 {\/* \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043f\u043e\u043b\u044f*\/}                 &lt;Field name=&quot;title&quot; component={this.renderField}  label=&quot;\u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a&quot; type=&quot;text&quot;\/&gt;                 &lt;Field name=&quot;text&quot; component={this.renderField}  label=&quot;\u0422\u0435\u043a\u0441\u0442&quot; type=&quot;text&quot;\/&gt;                 &lt;div&gt;                     &lt;button type=&quot;button&quot; onClick={reset}&gt;\u041e\u0447\u0438\u0441\u0442\u0438\u0442\u044c \u0444\u043e\u0440\u043c\u0443&lt;\/button&gt;                     &lt;button type=&quot;submit&quot;&gt;\u041e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0444\u043e\u0440\u043c\u0443&lt;\/button&gt;                 &lt;\/div&gt;             &lt;\/form&gt;         );     } } Form = reduxForm({     form: 'post' })(Form);  export default Form; <\/code><\/pre>\n<p>  <a href=\"http:\/\/redux-form.com\/6.1.1\/docs\/api\/Field.md\/\">\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435<\/a> \u043f\u0440\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 Field.<\/p>\n<p>  Redux-form \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0442\u0440\u0438 \u0432\u0438\u0434\u0430 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438:  <\/p>\n<ul>\n<li>\u0421\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f<\/li>\n<li>\u0410\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f<\/li>\n<li>\u0412\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u0430\u0431\u043c\u0438\u0442\u0430<\/li>\n<\/ul>\n<p>  \u0414\u043b\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b formValidate.js:  <\/p>\n<pre><code class=\"javascript\">\/\/ \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f export const validate = values =&gt; {     const errors = {};     if(!values.text){         errors.text = '\u041f\u043e\u043b\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f!';     } else if (values.text.length &lt; 15) {         errors.text = '\u0422\u0435\u043a\u0441\u0442 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 15 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432!'     }     \/\/ \u0434\u043b\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u043e \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438     return errors };  const sleep = ms =&gt; new Promise(resolve =&gt; setTimeout(resolve, ms)) \/\/\u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0430\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \/\/\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0434\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438 redux dispatch export const asyncValidate = (values\/*, dispatch *\/) =&gt; {     return sleep(1000) \/\/ \u0438\u043c\u0438\u0442\u0430\u0446\u0438\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0433\u043e \u043e\u0442\u0432\u0435\u0442\u0430         .then(() =&gt; {             if (!values.title) {                 \/\/ \u0434\u043b\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u043d\u0443\u0436\u043d\u043e \u0431\u0440\u043e\u0441\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439                 throw {title: '\u041f\u043e\u043b\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f!'}             } else if (values.title.length &gt; 10) {                 throw {title: '\u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 10 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432!'}             }         }) }; <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u0430\u0431\u043c\u0438\u0442\u0430 \u043d\u0443\u0436\u043d\u043e \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0441\u0430\u0431\u043c\u0438\u0442\u0430 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u043b \u043f\u0440\u043e\u043c\u0438\u0441:<\/p>\n<pre><code class=\"javascript\">import React, { Component }  from 'react'; \/\/ \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043a\u043b\u0430\u0441\u0441 \u043e\u0448\u0438\u0431\u043a\u0438 \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u044b import {initialize, SubmissionError} from 'redux-form'; import {connect} from 'react-redux'; import Form from '.\/Form';  const sleep = ms =&gt; new Promise(resolve =&gt; setTimeout(resolve, ms)); class EditPost extends Component{     constructor(props) {         super(props);     }         handleSubmit = (values) =&gt; {         \/* \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043f\u0440\u043e\u043c\u0438\u0441            erros \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043e\u0431\u044a\u0435\u043a\u0442, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043a\u043b\u044e\u0447 - \u044d\u0442\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u043e\u043b\u044f \u0441 \u043e\u0448\u0438\u0431\u043a\u043e\u0439            \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, {title: &quot;\u041d\u0435\u0432\u0435\u0440\u043d\u043e \u0432\u0432\u0435\u0434\u0435\u043d \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a&quot;}*\/         return sleep(1000) {\/\/ \u0441\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430}           .then(({errors, ...data}) =&gt; {              if (errors) {                 \/\/ \u0431\u0440\u043e\u0441\u0430\u0435\u043c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u0448\u0438\u0431\u043a\u0438 \u0441 \u0442\u0435\u043a\u0441\u0442\u0430\u043c\u0438 \u043e\u0448\u0438\u0431\u043e\u043a                 \/\/ _error \u043e\u0431\u0449\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u044b                 throw new SubmissionError({ ...errors, _error: '\u0421\u0442\u0430\u0442\u044c\u044f \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0430!' })              } else {                 \/\/ \u043e\u0448\u0438\u0431\u043e\u043a \u043d\u0435\u0442, \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 data             }        })     };     render() {         return (             &lt;div&gt;                 {\/* \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a*\/}                 &lt;Form onSubmit={this.handleSubmit} \/&gt;             &lt;\/div&gt;         );     } } function mapDispatchToProps(dispatch){     return {         initializePost: function (post){             dispatch(initialize('post', post));         }     } } function mapStateToProps(state, ownProps){     const id = ownProps.params.id;     return {        post: state.posts[id]     } } export default connect(mapStateToProps, mapDispatchToProps)(EditPost); <\/code><\/pre>\n<p>  \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044e \u0438 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0443\u0435\u043c \u0432\u044b\u0432\u043e\u0434 \u043e\u0448\u0438\u0431\u043e\u043a:  <\/p>\n<pre><code class=\"javascript\">import React, { Component } from 'react'; import { Field, reduxForm } from 'redux-form'; import {validate, asyncValidate} from '..\/formValidate';  class Form extends Component {    renderField = ({ input, label, type, meta: { touched, error, warning }}) =&gt; (         &lt;div&gt;             &lt;label&gt;{label}&lt;\/label&gt;             &lt;div&gt;                 &lt;input {...input} placeholder={label} type={type}\/&gt;                 {\/* \u043e\u0448\u0438\u0431\u043a\u0430 \u0434\u043b\u044f \u043f\u043e\u043b\u044f*\/}                 {touched && ((error && &lt;div&gt;{error}&lt;\/div&gt;))}             &lt;\/div&gt;         &lt;\/div&gt;     );     render(){         const {handleSubmit, reset, error} = this.props;          return (             &lt;form onSubmit={handleSubmit}&gt;                 {\/* \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 \u043f\u043e\u043b\u044f*\/}                 &lt;Field name=&quot;title&quot; component={this.renderField}  label=&quot;\u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a&quot; type=&quot;text&quot;\/&gt;                 &lt;Field name=&quot;text&quot; component={this.renderField}  label=&quot;\u0422\u0435\u043a\u0441\u0442&quot; type=&quot;text&quot;\/&gt;                 &lt;div&gt;                     &lt;button type=&quot;button&quot; onClick={reset}&gt;\u041e\u0447\u0438\u0441\u0442\u0438\u0442\u044c \u0444\u043e\u0440\u043c\u0443&lt;\/button&gt;                     &lt;button type=&quot;submit&quot;&gt;\u041e\u0442\u043f\u0440\u0430\u0432\u0438\u0442\u044c \u0444\u043e\u0440\u043c\u0443&lt;\/button&gt;                     {\/*\u043e\u0431\u0449\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u044b*\/}                     {error && &lt;div&gt;{error}&lt;\/div&gt;}                 &lt;\/div&gt;             &lt;\/form&gt;         );     } }  Form = reduxForm({     form: 'post',     \/\/ \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438     validate,     asyncValidate })(Form);  export default Form; <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u0445\u043e\u0447\u0435\u0442 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b, \u0434\u0435\u043b\u0430\u0435\u043c \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"bash\"> git clone https:\/\/github.com\/BoryaMogila\/koa_react_redux.git;  git checkout redux-form;  npm install;  npm run-script run-with-build; <\/code><\/pre>\n<p>  \u0418 \u043f\u0440\u043e\u0431\u0443\u0435\u043c CRUD \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c redux-form \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 localhost(127.0.0.1):4000\/app\/.<\/p>\n<p>  \u041f\u0440\u0438 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u0435\u043d \u043a\u043e\u043d\u0444\u0443\u0437: \u043f\u0440\u0438 \u043d\u0430\u0436\u0430\u0442\u0438\u0438 \u0441\u0430\u0431\u043c\u0438\u0442\u0430 \u0434\u043e \u043e\u0442\u0432\u0435\u0442\u0430 \u0441 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0441\u0430\u0431\u043c\u0438\u0442 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442.<br \/>  \u0412 <a href=\"http:\/\/redux-form.com\/6.1.1\/\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a> \u0435\u0441\u0442\u044c \u0435\u0449\u0435 \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0433\u043e \u0438 \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0433\u043e. \u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u044e \u043a \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0443.<br \/>  P.S.: \u041a\u0430\u043a \u0432\u0441\u0435\u0433\u0434\u0430 \u0436\u0434\u0443 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u0438\u0432\u0430.<br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/313966\/\"> https:\/\/habrahabr.ru\/post\/313966\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0414\u0443\u043c\u0430\u044e, \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0437\u043d\u0430\u0435\u0442 \u0441\u0445\u0435\u043c\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 redux: <br \/>  view -&gt; action -&gt; middlewares -&gt; reducers -&gt; state -&gt; view<br \/>  \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438 <a href=\"https:\/\/habrahabr.ru\/company\/mailru\/blog\/303456\/\">\u0437\u0434\u0435\u0441\u044c<\/a><br \/>  \u0425\u043e\u0447\u0443 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432\u0430\u0448\u0435\u043c\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e \u0442\u043e\u043c\u0443 \u0436\u0435 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 \u0434\u043b\u044f \u0444\u043e\u0440\u043c.<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/post_images\/fe5\/b38\/6c0\/fe5b386c0433052c00b4dd266fbbfe27.jpg\" alt=\"image\"\/>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-280269","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/280269","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=280269"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/280269\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=280269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=280269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=280269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}