{"id":228348,"date":"2022-10-12T18:16:00","date_gmt":"2022-10-12T15:16:00","guid":{"rendered":"https:\/\/wordpress.mediadoma.com\/?p=228348"},"modified":"2022-11-09T01:59:56","modified_gmt":"2022-11-08T22:59:56","slug":"peretvorennja-react-createclass-na-react-component","status":"publish","type":"post","link":"https:\/\/wordpress.mediadoma.com\/uk\/peretvorennja-react-createclass-na-react-component\/","title":{"rendered":"\u041f\u0435\u0440\u0435\u0442\u0432\u043e\u0440\u0435\u043d\u043d\u044f React.createClass \u043d\u0430 React.Component"},"content":{"rendered":"\n<p>\u0423 \u0441\u0432\u043e\u0457\u0439 <a href=\"https:\/\/wholesomecode.ltd\/blog\/broken-react-createclass-component-lets-fix-it\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">\u043e\u0441\u0442\u0430\u043d\u043d\u0456\u0439 \u0441\u0442\u0430\u0442\u0442\u0456 \u044f \u0440\u043e\u0437\u043f\u043e\u0432\u0456\u0434\u0430\u0432 \u043f\u0440\u043e \u0432\u0438\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044f \u0441\u0442\u0430\u0440\u0438\u0445 \u0432\u0435\u0440\u0441\u0456\u0439 React \u0434\u043b\u044f \u0440\u043e\u0431\u043e\u0442\u0438 \u0432 \u0441\u0443\u0447\u0430\u0441\u043d\u043e\u043c\u0443 \u0441\u0435\u0440\u0435\u0434\u043e\u0432\u0438\u0449\u0456<\/a>. \u0423 \u0446\u0456\u0439 \u0441\u0442\u0430\u0442\u0442\u0456 \u044f \u0439\u0434\u0443 \u0449\u0435 \u0434\u0430\u043b\u0456 \u0442\u0430 \u0434\u0430\u044e \u043f\u043e\u043a\u0440\u043e\u043a\u043e\u0432\u0438\u0439 \u043f\u043e\u0441\u0456\u0431\u043d\u0438\u043a \u0456\u0437 \u043e\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044f \u043a\u043b\u0430\u0441\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 React \u0434\u043e \u0441\u0443\u0447\u0430\u0441\u043d\u043e\u0433\u043e, \u0437\u043c\u0456\u043d\u0438\u0432\u0448\u0438 <code>React.createClass<\/code>\u0441\u043f\u043e\u0441\u0456\u0431 \u0432\u0438\u043a\u043e\u043d\u0430\u043d\u043d\u044f \u0437\u0430\u0432\u0434\u0430\u043d\u044c \u043d\u0430 \u0441\u0443\u0447\u0430\u0441\u043d\u0438\u0439 \u0456 \u0431\u0430\u0436\u0430\u043d\u0438\u0439 <code>React.Component<\/code>\u043c\u0435\u0442\u043e\u0434.<\/p>\n<p>\u0424\u0430\u0439\u043b\u0438, \u044f\u043a\u0456 \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0456\u0431\u043d\u0456, \u0431\u0443\u0434\u0443\u0442\u044c \u0443 \u043f\u0430\u043f\u043a\u0430\u0445 \u00abOriginal\u00bb \u0456 \u00abFinal\u00bb \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0443 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0456\u0432 \u0443 \u0441\u0443\u043f\u0440\u043e\u0432\u0456\u0434\u043d\u043e\u043c\u0443 \u0440\u0456\u0448\u0435\u043d\u043d\u0456 GitHub.<\/p>\n<p><a href=\"https:\/\/github.com\/mattwatsoncodes\/Tutorial-Convert-React-createClass-to-React-Component\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">\u041e\u0442\u0440\u0438\u043c\u0430\u0439\u0442\u0435 \u043d\u0430\u0432\u0447\u0430\u043b\u044c\u043d\u0456 \u0444\u0430\u0439\u043b\u0438 \u0437 GitHub<\/a><\/p>\n<p>\u0417\u043d\u043e\u0432\u0443 \u043f\u0440\u0430\u0446\u044e\u0454\u043c\u043e \u0437 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u043e\u043c <code>[react-checkbox-list](https:\/\/github.com\/sonyan\/react-checkbox-list)<\/code> <a href=\"https:\/\/github.com\/sonyan\/react-checkbox-list\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">Sony An<\/a> (\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0438\u0439 \u044f\u043a <a href=\"https:\/\/www.npmjs.com\/package\/react-checkbox-list\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\"><code>react-checkbox-list<\/code>\u043d\u0430 npm<\/a> ). \u0423 \u0446\u044c\u043e\u043c\u0443 \u043f\u043e\u0441\u0456\u0431\u043d\u0438\u043a\u0443 \u043a\u0440\u043e\u043a \u0437\u0430 \u043a\u0440\u043e\u043a\u043e\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e, \u044f\u043a \u0437\u0430\u043c\u0456\u043d\u0438\u0442\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0442\u0430 \u043c\u0435\u0442\u043e\u0434\u0438 \u043a\u043b\u0430\u0441\u0438\u0447\u043d\u043e\u0433\u043e <code>React.createClass<\/code>\u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043d\u0430 \u0441\u0443\u0447\u0430\u0441\u043d\u0438\u0439 <code>React.Component<\/code>.<\/p>\n<p>\u041f\u043e\u0447\u0438\u043d\u0430\u044e\u0447\u0438 \u0437 <code>.jsx<\/code>\u0444\u0430\u0439\u043b\u0443 \u0432 <code>react-checkbox-list<\/code>\u0440\u0456\u0448\u0435\u043d\u043d\u0456, \u043c\u0438 \u0441\u043f\u043e\u0447\u0430\u0442\u043a\u0443 \u0432\u0438\u0434\u0430\u043b\u0438\u043c\u043e <code>.js<\/code>\u0444\u0430\u0439\u043b \u0456 \u043f\u0435\u0440\u0435\u0439\u043c\u0435\u043d\u0443\u0454\u043c\u043e \u0439\u043e\u0433\u043e \u043d\u0430 <code>.js<\/code>, \u043e\u0441\u043a\u0456\u043b\u044c\u043a\u0438 <code>.jsx<\/code>\u0444\u0430\u0439\u043b\u0438 \u0431\u0456\u043b\u044c\u0448\u0435 \u043d\u0435 \u043f\u043e\u0432\u0438\u043d\u043d\u0456 \u043d\u0430\u0437\u0438\u0432\u0430\u0442\u0438\u0441\u044f \u0456\u043d\u0430\u043a\u0448\u0435.<\/p>\n<p>\u0426\u0435 \u0434\u0430\u0454 \u043d\u0430\u043c \u043d\u0430\u0441\u0442\u0443\u043f\u043d\u0438\u0439 \u043f\u043e\u0447\u0430\u0442\u043a\u043e\u0432\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<pre><code>\n'use strict';\nvar React = require('react');\n\nmodule.exports = React.createClass({\n    displayName: 'CheckBoxList',\n\n    propTypes: {\n        defaultData: React.PropTypes.array,\n        onChange: React.PropTypes.func\n    },\n\n    getInitialState: function() {\n        return {\n            data: this.props.defaultData || []\n        };\n    },\n\n    handleItemChange: function(e) {\n        var selectedValues = [],\n            newData = [];\n\n        this.state.data.forEach(function(item) {\n            if(item.value === e.target.value) {\n                item.checked = e.target.checked;\n            }\n            if(item.checked) {\n                selectedValues.push(item.value);\n            }\n            newData.push(item);\n        });\n\n        this.setState({data: newData});\n\n        if(this.props.onChange) {\n            this.props.onChange(selectedValues);\n        }\n    },\n\n    reset: function() {\n        var newData = [];\n        this.state.data.forEach(function(item) {\n            item.checked = false;\n            newData.push(item);\n        });\n\n        this.setState({data: newData});\n    },\n\n    checkAll: function() {\n        var newData = [];\n        this.state.data.forEach(function(item) {\n            item.checked = true;\n            newData.push(item);\n        });\n\n        this.setState({data: newData});\n    },\n\n    render: function() {\n        var options;\n\n        options = this.state.data.map(function(item, index) {\n            return (&lt;div key={'chk-' + index} className=\"checkbox\"&gt;\n                    &lt;label&gt;\n                        &lt;input\n                            type=\"checkbox\"\n                            value={item.value}\n                            onChange={this.handleItemChange}\n                            checked={item.checked? true: false} \/&gt; {item.label}\n                    &lt;\/label&gt;\n                &lt;\/div&gt;\n            );\n        }.bind(this));\n\n        return (&lt;div&gt;\n                {options}\n            &lt;\/div&gt;\n        );\n    }\n});\n<\/code><\/pre>\n<h2>\u041f\u0435\u0440\u0435\u0442\u0432\u043e\u0440\u0435\u043d\u043d\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430<\/h2>\n<p>\u041f\u0456\u0434 \u0447\u0430\u0441 \u0441\u043f\u0440\u043e\u0431\u0438 \u0437\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0438\u0442\u0438 \u0446\u0435\u0439 \u043a\u043e\u0434 \u043f\u0435\u0440\u0448\u0430 \u043f\u043e\u043c\u0438\u043b\u043a\u0430, \u044f\u043a\u0443 \u043c\u0438 \u043e\u0442\u0440\u0438\u043c\u0443\u0454\u043c\u043e:<code>Uncaught Error: Module build failed: SyntaxError: The @jsx React.DOM pragma has been deprecated as of React 0.12<\/code><\/p>\n<p>\u041d\u0435\u0432\u043b\u043e\u0432\u043b\u0435\u043d\u0430 \u200b\u200b\u043f\u043e\u043c\u0438\u043b\u043a\u0430: \u043d\u0435 \u0432\u0434\u0430\u043b\u043e\u0441\u044f \u0441\u0442\u0432\u043e\u0440\u0438\u0442\u0438 \u043c\u043e\u0434\u0443\u043b\u044c: SyntaxError: \u041f\u0440\u0430\u0433\u043c\u0430 <a href=\"https:\/\/hashnode.com\/@jsx\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">@jsx<\/a> React.DOM \u0437\u0430\u0441\u0442\u0430\u0440\u0456\u043b\u0430 \u0437 React 0.12<\/p>\n<p>\u0412\u0438\u043f\u0440\u0430\u0432\u0438\u0442\u0438 \u0446\u0435 \u0434\u043e\u0441\u0438\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e. \u041f\u0440\u043e\u0441\u0442\u043e \u043f\u0440\u0438\u0431\u0435\u0440\u0456\u0442\u044c \u0440\u044f\u0434\u043e\u043a <code>\/** @jsx React.DOM *\/<\/code>\u0443 \u0432\u0435\u0440\u0445\u043d\u0456\u0439 \u0447\u0430\u0441\u0442\u0438\u043d\u0456 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440 \u043c\u0438 \u043e\u0442\u0440\u0438\u043c\u0443\u0454\u043c\u043e \u0442\u0430\u043a\u0443 <code>Uncaught TypeError: Cannot read property 'array' of undefined<\/code>\u0441\u0430\u043c\u0443 \u043f\u043e\u043c\u0438\u043b\u043a\u0443, \u044f\u043a \u0443 <a href=\"https:\/\/wholesomecode.ltd\/blog\/broken-react-createclass-component-lets-fix-it\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">\u043f\u043e\u0441\u0456\u0431\u043d\u0438\u043a\u0443 \u0437<\/a> <a href=\"https:\/\/wholesomecode.ltd\/blog\/broken-react-createclass-component-lets-fix-it\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">\u0432\u0438\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044f<\/a>. \u0426\u0435 \u043f\u043e\u044f\u0441\u043d\u044e\u0454\u0442\u044c\u0441\u044f \u0442\u0438\u043c, \u0449\u043e React.propTypes \u0437\u0430\u0441\u0442\u0430\u0440\u0456\u0432 \u0443 React \u0432\u0435\u0440\u0441\u0456\u0457 15.50, \u0442\u043e\u043c\u0443, \u0437\u0433\u0456\u0434\u043d\u043e \u0437 \u0446\u0438\u043c \u043f\u0456\u0434\u0440\u0443\u0447\u043d\u0438\u043a\u043e\u043c, \u0432\u0441\u0442\u0430\u043d\u043e\u0432\u0456\u0442\u044c \u043f\u0430\u043a\u0435\u0442 PropTypes \u0437\u0430 \u0434\u043e\u043f\u043e\u043c\u043e\u0433\u043e\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0438 \u0447\u0435\u0440\u0435\u0437 npm. \u041c\u0438 \u0456\u043c\u043f\u043e\u0440\u0442\u0443\u0454\u043c\u043e \u0446\u0435 \u0432 \u043d\u0430\u0448 \u043f\u0430\u043a\u0435\u0442 \u043f\u0456\u0437\u043d\u0456\u0448\u0435.<code>[React.createClass](https:\/\/wholesomecode.ltd\/blog\/broken-react-createclass-component-lets-fix-it\/)<\/code><a href=\"https:\/\/wholesomecode.ltd\/blog\/broken-react-createclass-component-lets-fix-it\/\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external\"><\/a><\/p>\n<pre><code>npm install --save prop-types\n<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440 \u0441\u043b\u0456\u0434 \u043f\u043e\u0432\u043d\u0456\u0441\u0442\u044e \u043f\u0435\u0440\u0435\u0440\u043e\u0431\u0438\u0442\u0438 \u043a\u043e\u0434\u043e\u0432\u0443 \u0431\u0430\u0437\u0443, \u0442\u043e\u043c\u0443 \u043c\u0438 \u043d\u0435 \u043c\u043e\u0436\u0435\u043c\u043e \u043e\u043d\u043e\u0432\u0438\u0442\u0438 \u0442\u0430 \u0432\u0438\u043f\u0440\u0430\u0432\u0438\u0442\u0438 \u043f\u043e\u043c\u0438\u043b\u043a\u0443, \u044f\u043a \u043c\u0438, \u043c\u043e\u0436\u043b\u0438\u0432\u043e, \u0440\u043e\u0431\u0438\u043b\u0438 \u0440\u0430\u043d\u0456\u0448\u0435, \u0442\u043e\u043c\u0443 \u043c\u0438 \u043d\u0435 \u0437\u043d\u0430\u0442\u0438\u043c\u0435\u043c\u043e, \u0447\u0438 \u0432\u043e\u043d\u0430 \u0441\u043f\u0440\u0430\u0446\u044e\u0432\u0430\u043b\u0430 \u0434\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u043a\u0456\u043d\u0446\u044f. \u041f\u0440\u0438\u0441\u0442\u0435\u0431\u043d\u0456\u0442\u044c\u0441\u044f!<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0447\u043d\u0435\u043c\u043e \u0456\u0437 \u0437\u0430\u043c\u0456\u043d\u0438 <code>React.createClass<\/code>\u0444\u0443\u043d\u043a\u0446\u0456\u0457 \u043d\u0430 \u043e\u0433\u043e\u043b\u043e\u0448\u0435\u043d\u043d\u044f \u043d\u043e\u0432\u043e\u0433\u043e <code>React.Component<\/code>. \u0417\u043c\u0456\u043d\u0456\u0442\u044c \u043d\u0430\u0448 \u043a\u043e\u0434, \u0449\u043e\u0431 \u0432\u0456\u043d \u0432\u0438\u0433\u043b\u044f\u0434\u0430\u0432 \u0442\u0430\u043a:<\/p>\n<pre><code>'use strict';\nimport React from 'react';\n\nclass CheckBoxList extends React.Component {\n...\n}\n<\/code><\/pre>\n<p>\u0417\u0432\u0435\u0440\u043d\u0456\u0442\u044c \u0443\u0432\u0430\u0433\u0443, \u0449\u043e \u0442\u0443\u0442 \u043c\u0438 \u0437\u0440\u043e\u0431\u0438\u043b\u0438 \u043a\u0456\u043b\u044c\u043a\u0430 \u0440\u0435\u0447\u0435\u0439:<\/p>\n<ul>\n<li>\u0412\u0438\u0434\u0430\u043b\u0435\u043d\u043e \u043f\u043e\u0447\u0430\u0442\u043a\u043e\u0432\u0438\u0439 \u043a\u043e\u043c\u0435\u043d\u0442\u0430\u0440 JSX<\/li>\n<li>\u0417\u043c\u0456\u043d\u0435\u043d\u043e \u0442\u0438\u043f \u043e\u0433\u043e\u043b\u043e\u0448\u0435\u043d\u043d\u044f \u0437 <code>var React =...<\/code>\u043d\u0430 <code>import React from 'react';<\/code>\u0446\u0435 \u0441\u0443\u0447\u0430\u0441\u043d\u0438\u0439 \u0441\u043f\u043e\u0441\u0456\u0431 \u0441\u0442\u0432\u043e\u0440\u0435\u043d\u043d\u044f \u043e\u0433\u043e\u043b\u043e\u0448\u0435\u043d\u044c \u0443 React.<\/li>\n<li>\u0422\u0435\u043f\u0435\u0440 \u043c\u0438 \u043e\u0433\u043e\u043b\u043e\u0448\u0443\u0454\u043c\u043e \u043d\u043e\u0432\u0438\u0439 \u043a\u043b\u0430\u0441 <code>CheckBoxList<\/code>\u0437\u0430\u043c\u0456\u0441\u0442\u044c \u0435\u043a\u0441\u043f\u043e\u0440\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0456\u0457.<\/li>\n<li>\u0427\u0435\u0440\u0435\u0437 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 \u043e\u0431&#8217;\u0454\u043a\u0442\u0430, \u044f\u043a\u0438\u0439 \u0437\u0430\u0440\u0430\u0437 \u0443\u0437\u044f\u0442\u0438\u0439 \u0443 \u0434\u0443\u0436\u043a\u0438 <code>{...}<\/code>, \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0456\u0431\u043d\u043e \u0432\u0456\u0434\u043a\u0438\u043d\u0443\u0442\u0438 \u0437\u0430\u043a\u0440\u0438\u0442\u0442\u044f<code>);<\/code><\/li>\n<\/ul>\n<p>\u041e\u0434\u043d\u0430\u043a \u0446\u0435\u0439 \u043d\u043e\u0432\u0438\u0439 \u043a\u043b\u0430\u0441 \u0442\u0435\u043f\u0435\u0440 \u043d\u0435 \u043c\u0430\u0454 \u0441\u043f\u043e\u0441\u043e\u0431\u0443 \u0439\u043e\u0433\u043e \u0435\u043a\u0441\u043f\u043e\u0440\u0442\u0443, \u0449\u043e\u0431 \u0456\u043d\u0448\u0456 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0438 \u043c\u043e\u0433\u043b\u0438 \u0439\u043e\u0433\u043e \u0432\u0438\u043a\u043e\u0440\u0438\u0441\u0442\u043e\u0432\u0443\u0432\u0430\u0442\u0438, \u0442\u043e\u043c\u0443 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043e\u0434\u0430\u043c\u043e \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0446\u0456\u044e \u0435\u043a\u0441\u043f\u043e\u0440\u0442\u0443 \u0432\u043d\u0438\u0437\u0443 \u0446\u044c\u043e\u0433\u043e \u043a\u043e\u0434\u0443.<\/p>\n<pre><code>'use strict';\nimport React from 'react';\n\nclass CheckBoxList extends React.Component {\n...\n}\n\nexport default CheckBoxList;\n<\/code><\/pre>\n<p>\u0423 \u043d\u0430\u0448\u043e\u043c\u0443 \u043e\u0440\u0438\u0433\u0456\u043d\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043a\u043e\u0434\u0456 \u043f\u0435\u0440\u0448\u0438\u0439 \u0440\u044f\u0434\u043e\u043a \u043a\u043e\u0434\u0443 \u0443 \u0444\u0443\u043d\u043a\u0446\u0456\u0457 \u0431\u0443\u0432 <code>displayName: 'CheckBoxList',<\/code>\u043d\u0430\u0448\u0438\u043c \u0435\u043a\u0441\u043f\u043e\u0440\u0442\u043e\u043c, \u044f\u043a\u0438\u0439 \u0442\u0435\u043f\u0435\u0440 \u043e\u0431\u0440\u043e\u0431\u043b\u044f\u0454 \u0446\u0435, \u0442\u043e\u043c\u0443 \u043c\u0438 \u043c\u043e\u0436\u0435\u043c\u043e \u043f\u043e\u0432\u043d\u0456\u0441\u0442\u044e \u0432\u0438\u0434\u0430\u043b\u0438\u0442\u0438 \u0446\u0435\u0439 \u043a\u043e\u0434.<\/p>\n<p>\u041d\u0430\u0441\u0442\u0443\u043f\u043d\u0438\u0439 \u0440\u044f\u0434\u043e\u043a \u043e\u0433\u043e\u043b\u043e\u0448\u0443\u0454, \u0449\u043e <code>propTypes<\/code>\u0446\u0456 \u0442\u0435\u043f\u0435\u0440 \u0437\u043d\u0430\u0445\u043e\u0434\u044f\u0442\u044c\u0441\u044f \u043f\u043e\u0437\u0430 \u043a\u043b\u0430\u0441\u043e\u043c \u0456 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u044e\u0442\u044c <code>PropTypes<\/code>\u0437\u0430\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u0456, \u044f\u043a\u0443 \u043c\u0438 \u0434\u043e\u0434\u0430\u043b\u0438 \u0447\u0435\u0440\u0435\u0437 npm. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0434\u043e\u0434\u0430\u043c\u043e \u0446\u0435 \u0434\u043e \u043d\u0430\u0448\u043e\u0433\u043e \u0456\u043c\u043f\u043e\u0440\u0442\u0443 \u0442\u0430 \u043d\u0430\u043f\u0438\u0448\u0435\u043c\u043e PropTypes \u0442\u0430\u043a:<\/p>\n<pre><code>'use strict';\nimport React from 'react';\nimport PropTypes from 'prop-types';\n\nclass CheckBoxList extends React.Component {\n...\n}\n\nCheckBoxList.propTypes = {\n    defaultData: PropTypes.array,\n    onChange: PropTypes.func,\n};\n\nexport default CheckBoxList;\n<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0456 \u0441\u0442\u0430\u043d \u043e\u0433\u043e\u043b\u043e\u0448\u0443\u0454\u0442\u044c\u0441\u044f \u0437\u0430 \u0434\u043e\u043f\u043e\u043c\u043e\u0433\u043e\u044e \u043c\u0435\u0442\u043e\u0434\u0443, <code>getInitialState<\/code>\u0437\u0430 \u0434\u043e\u043f\u043e\u043c\u043e\u0433\u043e\u044e \u044f\u043a\u043e\u0433\u043e <code>React.Component<\/code>\u043c\u0438 \u0432\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u044e\u0454\u043c\u043e \u043f\u043e\u0447\u0430\u0442\u043a\u043e\u0432\u0438\u0439 \u0441\u0442\u0430\u043d \u0437\u0430 \u0434\u043e\u043f\u043e\u043c\u043e\u0433\u043e\u044e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430. \u0414\u043e\u0434\u0430\u0439\u0442\u0435 \u043d\u0430\u0441\u0442\u0443\u043f\u043d\u0438\u0439 \u043a\u043e\u0434 \u0443 \u043d\u0430\u0448\u0443 \u0437\u0431\u0456\u0440\u043a\u0443:<\/p>\n<pre><code>...\nclass CheckBoxList extends React.Component {\n    constructor( props) {\n        super( props );\n        this.state = {\n            data: [],\n        }\n    }\n...\n}\n...\n<\/code><\/pre>\n<p>\u041e\u0442\u0436\u0435, \u0446\u0435 \u0432\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u044e\u0454 \u0441\u0442\u0430\u043d \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u0430\u043b\u0435 \u0447\u0435\u043a\u0430\u0439\u0442\u0435, \u043c\u0438 \u043d\u0430\u0441\u043f\u0440\u0430\u0432\u0434\u0456 \u043d\u0435 \u0441\u043a\u0430\u0437\u0430\u043b\u0438 \u0439\u043e\u043c\u0443, \u0437\u0432\u0456\u0434\u043a\u0438 \u043e\u0442\u0440\u0438\u043c\u0430\u0442\u0438 \u0441\u0432\u0456\u0439 \u0441\u0442\u0430\u043d. \u041e\u0441\u044c \u0434\u0435 <code>componentWillMount<\/code>\u0441\u0442\u0430\u043d\u0435 \u0432 \u043d\u0430\u0433\u043e\u0434\u0456.<\/p>\n<pre><code>...\nclass CheckBoxList extends React.Component {\n    constructor( props) {\n        super( props );\n        this.state = {\n            data: [],\n        }\n    }\n\n    componentWillMount() {\n        this.setState({\n            data: this.props.defaultData,\n        });\n    }\n...\n}\n...\n<\/code><\/pre>\n<p>\u0412\u0430\u0436\u043b\u0438\u0432\u043e \u0437\u0430\u0443\u0432\u0430\u0436\u0438\u0442\u0438, \u0449\u043e \u0432\u043d\u0443\u0442\u0440\u0456\u0448\u043d\u0456 \u043c\u0435\u0442\u043e\u0434\u0438 <code>React.Component<\/code>\u043d\u0435 \u0437\u0430\u043a\u0456\u043d\u0447\u0443\u044e\u0442\u044c\u0441\u044f \u043a\u043e\u043c\u0430\u043c\u0438 (<code>,<\/code>), \u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0435\u043a\u043e\u043d\u0430\u0439\u0442\u0435\u0441\u044f, \u0449\u043e \u0432\u0441\u0456 \u043c\u0435\u0442\u043e\u0434\u0438, \u044f\u043a\u0456 \u0432\u0438 \u0434\u043e\u0434\u0430\u0454\u0442\u0435 \u0434\u043e \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430, \u043d\u0435 \u0437\u0430\u043a\u0456\u043d\u0447\u0443\u044e\u0442\u044c\u0441\u044f \u043a\u043e\u043c\u0430\u043c\u0438!<\/p>\n<p>\u0414\u0430\u043b\u0456, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u043d\u043e\u0432\u0443 \u0434\u043e\u0434\u0430\u043c\u043e \u0444\u0443\u043d\u043a\u0446\u0456\u044e \u0440\u0435\u043d\u0434\u0435\u0440\u0438\u043d\u0433\u0443. \u0426\u0435, \u043c\u0430\u0431\u0443\u0442\u044c, \u043d\u0430\u0439\u043f\u0440\u043e\u0441\u0442\u0456\u0448\u0430 \u0447\u0430\u0441\u0442\u0438\u043d\u0430, \u0432\u043e\u043d\u0430 \u043c\u0430\u0439\u0436\u0435 \u0442\u0430\u043a\u0430 \u0441\u0430\u043c\u0430, \u0437 \u0442\u0456\u0454\u044e \u043a\u043b\u044e\u0447\u043e\u0432\u043e\u044e \u0440\u0456\u0437\u043d\u0438\u0446\u0435\u044e, \u0449\u043e \u043c\u0438 \u0437\u043c\u0456\u043d\u044e\u0454\u043c\u043e <code>render: function() {<\/code>\u0457\u0457 \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e <code>render() {<\/code>.<\/p>\n<pre><code>...\nclass CheckBoxList extends React.Component {\n...\n    render() {\n        var options;\n\n        options = this.state.data.map(function(item, index) {\n            return (&lt;div key={'chk-' + index} className=\"checkbox\"&gt;\n                    &lt;label&gt;\n                        &lt;input\n                            type=\"checkbox\"\n                            value={item.value}\n                            onChange={this.handleItemChange}\n                            checked={item.checked? true: false} \/&gt; {item.label}\n                    &lt;\/label&gt;\n                &lt;\/div&gt;\n            );\n        }.bind(this));\n\n        return (&lt;div&gt;\n                {options}\n            &lt;\/div&gt;\n        );\n    }\n...\n}\n...\n<\/code><\/pre>\n<p>\u0429\u043e\u0431 \u0437\u0431\u0435\u0440\u0435\u0433\u0442\u0438 \u0437\u043c\u0456\u0441\u0442 \u0446\u044c\u043e\u0433\u043e \u043f\u0456\u0434\u0440\u0443\u0447\u043d\u0438\u043a\u0430, \u044f \u043d\u0435 \u0431\u0443\u0434\u0443 \u043f\u0435\u0440\u0435\u0442\u0432\u043e\u0440\u044e\u0432\u0430\u0442\u0438 \u0446\u0456 \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0438 <code>reset<\/code>, <code>checkAll<\/code>\u043e\u0434\u043d\u0430\u043a \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0456\u0457, \u0432\u0438\u043a\u043e\u0440\u0438\u0441\u0442\u0430\u043d\u0456 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0435\u043d\u043d\u044f \u043c\u0435\u0442\u043e\u0434\u0443 <code>handleItemChange<\/code>apple, \u043f\u0456\u0434\u0445\u043e\u0434\u044f\u0442\u044c \u0434\u043b\u044f \u043e\u0431\u043e\u0445, \u0442\u043e\u0436 \u043d\u0435 \u0441\u043e\u0440\u043e\u043c\u0442\u0435\u0441\u044f \u0441\u043f\u0440\u043e\u0431\u0443\u0432\u0430\u0442\u0438 \u0457\u0445 \u0441\u0430\u043c\u043e\u0441\u0442\u0456\u0439\u043d\u043e.<\/p>\n<p>\u0429\u043e\u0431 \u043f\u0435\u0440\u0435\u043d\u0435\u0441\u0442\u0438 <code>handleItemChange<\/code>\u043c\u0435\u0442\u043e\u0434, \u043d\u0430\u043c \u0441\u043f\u043e\u0447\u0430\u0442\u043a\u0443 \u043f\u043e\u0442\u0440\u0456\u0431\u043d\u043e \u0432\u0438\u0434\u0430\u043b\u0438\u0442\u0438 \u043a\u0456\u043d\u0446\u0435\u0432\u0443 \u043a\u043e\u043c\u0443 (<code>,<\/code>) \u0456 \u0437\u043c\u0456\u043d\u0438\u0442\u0438 \u0442\u0438\u043f \u043e\u0433\u043e\u043b\u043e\u0448\u0435\u043d\u043d\u044f \u0444\u0443\u043d\u043a\u0446\u0456\u0457 \u0437 <code>handleItemChange: function(e) {<\/code>\u043d\u0430 <code>handleItemChange( e) {<\/code>\u043f\u0435\u0440\u0435\u043a\u043e\u043d\u0430\u0432\u0448\u0438\u0441\u044c, \u0449\u043e \u043c\u0438 \u0432\u0441\u0435 \u0449\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0454\u043c\u043e <code>e<\/code>\u044f\u043a \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u043f\u043e\u0434\u0456\u0457.<\/p>\n<p>\u0414\u043e\u0434\u0430\u043c\u043e \u0446\u0435 \u043d\u0430\u0434 \u043d\u0430\u0448\u0438\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u0432\u0456\u0437\u0443\u0430\u043b\u0456\u0437\u0430\u0446\u0456\u0457.<\/p>\n<pre><code>...\nclass CheckBoxList extends React.Component {\n...\n    handleItemChange( e) {\n        var selectedValues = [],\n            newData = [];\n\n        this.state.data.forEach(function(item) {\n            if(item.value == e.target.value) {\n                item.checked = e.target.checked;\n            }\n            if(item.checked) {\n                selectedValues.push(item.value);\n            }\n            newData.push(item);\n        });\n\n        this.setState( {data: newData} );\n\n        if(this.props.onChange) {\n            this.props.onChange(selectedValues);\n        }\n    }\n...\n}\n...\n<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440 \u043d\u0430\u0448 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 \u0432\u0456\u0434\u0442\u0432\u043e\u0440\u044e\u0432\u0430\u0442\u0438\u043c\u0435\u0442\u044c\u0441\u044f, \u0430\u043b\u0435 \u043d\u0435 \u043f\u0440\u0430\u0446\u044e\u0432\u0430\u0442\u0438\u043c\u0435. \u041a\u043e\u043b\u0438 \u0432\u0438 \u0441\u043f\u0440\u043e\u0431\u0443\u0454\u0442\u0435 \u043d\u0430\u0442\u0438\u0441\u043d\u0443\u0442\u0438 \u043f\u0440\u0430\u043f\u043e\u0440\u0435\u0446\u044c, \u0432\u0438 \u043e\u0442\u0440\u0438\u043c\u0430\u0454\u0442\u0435 \u043f\u043e\u0432\u0456\u0434\u043e\u043c\u043b\u0435\u043d\u043d\u044f \u043f\u0440\u043e \u043f\u043e\u043c\u0438\u043b\u043a\u0443 <code>Uncaught TypeError: Cannot read property 'state' of undefined<\/code>.<\/p>\n<p>Uncaught TypeError: \u043d\u0435\u043c\u043e\u0436\u043b\u0438\u0432\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u0438 \u0432\u043b\u0430\u0441\u0442\u0438\u0432\u0456\u0441\u0442\u044c &#8216;state&#8217; \u043d\u0435\u0432\u0438\u0437\u043d\u0430\u0447\u0435\u043d\u043e\u0433\u043e<\/p>\n<p>\u0426\u0435 \u0442\u043e\u043c\u0443, \u0449\u043e \u0432 \u043d\u0430\u0448\u043e\u043c\u0443 <code>handleItemChange<\/code>\u043c\u0435\u0442\u043e\u0434\u0456, \u0434\u0435 \u043c\u0438 \u043d\u0430\u043c\u0430\u0433\u0430\u0454\u043c\u043e\u0441\u044f \u043e\u0442\u0440\u0438\u043c\u0430\u0442\u0438 \u0434\u043e\u0441\u0442\u0443\u043f \u0434\u043e \u0441\u0442\u0430\u043d\u0443, <code>this<\/code>\u043d\u0435 \u0432\u0438\u0437\u043d\u0430\u0447\u0435\u043d\u043e. \u0429\u043e\u0431 \u0432\u0438\u043f\u0440\u0430\u0432\u0438\u0442\u0438 \u0446\u0435, \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0456\u0431\u043d\u043e \u043f\u0440\u0438\u0432\u2019\u044f\u0437\u0430\u0442\u0438 \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0456\u044e <code>this<\/code>, \u0434\u043e\u0434\u0430\u0432\u0448\u0438 \u0442\u0430\u043a\u0438\u0439 \u0440\u044f\u0434\u043e\u043a \u0443 \u043d\u0430\u0448 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440: <code>this.handleItemChange = this.handleItemChange.bind( this );<\/code>.<\/p>\n<pre><code>...\nclass CheckBoxList extends React.Component {\n    constructor( props) {\n        super( props );\n        this.state = {\n            data: [],\n        }\n        this.handleItemChange = this.handleItemChange.bind( this );\n    }\n...\n}\n...\n<\/code><\/pre>\n<p>\u0406 \u043e\u0441\u044c \u0432\u0456\u043d, \u043d\u0430\u0448 \u0449\u043e\u0439\u043d\u043e \u043f\u0435\u0440\u0435\u0442\u0432\u043e\u0440\u0435\u043d\u0438\u0439 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442 React \u0443 \u0434\u0456\u0457.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/wordpress.mediadoma.com\/wp-content\/uploads\/2022\/01\/post-169430-61e80f22b2772.gif\" alt=\"\u041f\u0435\u0440\u0435\u0442\u0432\u043e\u0440\u0435\u043d\u043d\u044f React.createClass \u043d\u0430 React.Component\" \/>React.createClass \u0434\u043e React.Component<\/p>\n<h2>\u0412\u0438\u0445\u0456\u0434\u043d\u0438\u0439 \u043a\u043e\u0434 \u043f\u0456\u0434\u0440\u0443\u0447\u043d\u0438\u043a\u0430<\/h2>\n<p>\u0412\u0438 \u043c\u043e\u0436\u0435\u0442\u0435 <a href=\"https:\/\/github.com\/wholesomecode\/Tutorial-Convert-React-createClass-to-React-Component\" target=\"_blank\" rel=\"noopener nofollow\" class=\"external external_icon\">\u0437\u0430\u0432\u0430\u043d\u0442\u0430\u0436\u0438\u0442\u0438 \u0432\u0438\u0445\u0456\u0434\u043d\u0438\u0439 \u043a\u043e\u0434 \u043e\u0440\u0438\u0433\u0456\u043d\u0430\u043b\u044c\u043d\u043e\u0457 \u0442\u0430 \u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e\u0457 \u0432\u0435\u0440\u0441\u0456\u0457 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043d\u0430 GitHub<\/a>. \u041f\u043b\u0430\u0433\u0456\u043d \u043c\u0456\u0441\u0442\u0438\u0442\u044c \u0431\u043b\u043e\u043a WordPress Gutenberg, \u044f\u043a\u0438\u0439 \u043c\u043e\u0436\u043d\u0430 \u0432\u0438\u043a\u043e\u0440\u0438\u0441\u0442\u043e\u0432\u0443\u0432\u0430\u0442\u0438, \u0449\u043e\u0431 \u043f\u043e\u0433\u0440\u0430\u0442\u0438 \u0437 \u043a\u043e\u0434\u043e\u043c, \u0456\u0437 \u0442\u0440\u044c\u043e\u043c\u0430 \u0444\u0430\u0439\u043b\u0430\u043c\u0438, \u044f\u043a\u0456 \u043c\u043e\u0436\u043d\u0430 \u0432\u0438\u0434\u0430\u043b\u0438\u0442\u0438, \u044f\u043a\u0449\u043e \u0446\u0435 \u043d\u0435\u043e\u0431\u0445\u0456\u0434\u043d\u043e:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/wordpress.mediadoma.com\/wp-content\/uploads\/2022\/01\/post-169430-61e80f247b7d4.png\" alt=\"\u041f\u0435\u0440\u0435\u0442\u0432\u043e\u0440\u0435\u043d\u043d\u044f React.createClass \u043d\u0430 React.Component\" \/>\u0424\u0430\u0439\u043b\u0438 \u043f\u043e\u0441\u0456\u0431\u043d\u0438\u043a\u0456\u0432 GitHub \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0442\u0432\u043e\u0440\u0435\u043d\u043d\u044f React.createClass \u0443 React.Component<\/p>\n<p><div id=\"PostUnique_PostSource\" style=\"padding-top: 50px\">\u0414\u0436\u0435\u0440\u0435\u043b\u043e \u0437\u0430\u043f\u0438\u0441\u0443:  <a target=\"_blank\" rel=\"noopener nofollow\" href=\"\/\/wholesomecode.ltd\" class=\"external external_icon\">wholesomecode.ltd<\/a><\/div><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0423 \u0441\u0432\u043e\u0457\u0439 \u043e\u0441\u0442\u0430\u043d\u043d\u0456\u0439 \u0441\u0442\u0430\u0442\u0442\u0456 \u044f \u0440\u043e\u0437\u043f\u043e\u0432\u0456\u0434\u0430\u0432 \u043f\u0440\u043e \u0432\u0438\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044f \u0441\u0442\u0430\u0440\u0438\u0445 \u0432\u0435\u0440\u0441\u0456\u0439 React \u0434\u043b\u044f \u0440\u043e\u0431\u043e\u0442\u0438 \u0432 \u0441\u0443\u0447\u0430\u0441\u043d\u043e\u043c\u0443 \u0441\u0435\u0440\u0435\u0434\u043e\u0432\u0438\u0449\u0456. \u0423 \u0446\u0456\u0439 \u0441\u0442\u0430\u0442\u0442\u0456 \u044f \u0439\u0434\u0443 \u0449\u0435 \u0434\u0430\u043b\u0456 \u0442\u0430 \u0434\u0430\u044e \u043f\u043e\u043a\u0440\u043e\u043a\u043e\u0432\u0438\u0439 \u043f\u043e\u0441\u0456\u0431\u043d\u0438\u043a \u0437 \u043e\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044f cl&#8230;<\/p>\n","protected":false},"author":1,"featured_media":224207,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_wp_rev_ctl_limit":""},"categories":[902,849,923,725],"tags":[1174],"class_list":["post-228348","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-kod-3","category-pidruchnyky","category-inshyj","category-rozrobnyk","tag-affiai-uk"],"_links":{"self":[{"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/posts\/228348","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/comments?post=228348"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/posts\/228348\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/media\/224207"}],"wp:attachment":[{"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/media?parent=228348"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/categories?post=228348"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wordpress.mediadoma.com\/uk\/wp-json\/wp\/v2\/tags?post=228348"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}