{"id":273702,"date":"2016-02-06T02:17:03","date_gmt":"2016-02-05T23:17:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=273702"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=273702","title":{"rendered":"\u041f\u0440\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 React \u0441 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c canvas"},"content":{"rendered":"<p>       \u0415\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a React, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u043c \u0438 \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u043c DOM \u0432 \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u043c \u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435. \u042d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a\u0440\u0443\u0442\u043e.<\/p>\n<p>  \u041d\u043e \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0440\u043e \u043e\u043f\u044b\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f React, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0439 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0435\u0439 \u043d\u0430\u0434 &quot;\u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u043c&quot; canvas \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c. \u0417\u0432\u0443\u0447\u0438\u0442 \u0441\u0442\u0440\u0430\u043d\u043d\u043e, \u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u043d\u043e.<\/p>\n<h2>\u041c\u043e\u0442\u0438\u0432\u0430\u0446\u0438\u044f<\/h2>\n<p>  \u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u044d\u043b\u0435\u043c\u0435\u043d\u0442 <code>&lt;canvas&gt;<\/code> \u043e\u0447\u0435\u043d\u044c \u0447\u0430\u0441\u0442\u043e. \u042f \u0441\u0434\u0435\u043b\u0430\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 canvas \u2014 \u044d\u0442\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c canvas \u0431\u0435\u0437 \u0432\u0441\u044f\u043a\u0438\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u043e \u0432 \u043a\u0440\u0443\u043f\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043d\u0430\u0447\u0430\u043b \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438. \u0421\u0435\u0439\u0447\u0430\u0441 \u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a <a href=\"http:\/\/konvajs.github.io\/\">Konva<\/a> (\u0435\u0441\u0442\u044c \u043e\u0431\u0437\u043e\u0440\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f <a href=\"https:\/\/habrahabr.ru\/post\/250897\/\"><a href=\"https:\/\/habrahabr.ru\/post\/250897\/\">https:\/\/habrahabr.ru\/post\/250897\/<\/a><\/a>).<\/p>\n<p>  Konva \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0441\u0438\u043b\u044c\u043d\u043e, \u043d\u043e \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e. \u0422\u0430\u043a \u0436\u0435 \u044f \u043d\u0430\u0447\u0430\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c React \u0432 \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445, \u0438 \u043e\u043d \u043c\u043d\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f. \u0418 \u044f \u043f\u043e\u0434\u0443\u043c\u0430\u043b, \u043a\u0430\u043a \u0436\u0435 \u044f \u043c\u043e\u0433\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c React \u0434\u043b\u044f \u0440\u0438\u0441\u043e\u0432\u0430\u043d\u0438\u044f \u0433\u0440\u0430\u0444\u0438\u043a\u0438 \u043d\u0430 canvas?<\/p>\n<p>  <a name=\"habracut\"><\/a>  <\/p>\n<h2>React + canvas \u0431\u0435\u0437 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432<\/h2>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0443 canvas \u0438\u0437 React \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0438 \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u043d\u0430\u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e:<\/p>\n<pre><code class=\"javascript\">class CanvasComponent extends React.Component {     componentDidMount() {         this.updateCanvas();     }     updateCanvas() {         const ctx = this.refs.canvas.getContext('2d');         ctx.fillRect(0,0, 100, 100);     }     render() {         return (             &lt;canvas ref=&quot;canvas&quot; width={300} height={300}\/&gt;         );     } } ReactDOM.render(&lt;CanvasComponent\/&gt;, document.getElementById('container'));<\/code><\/pre>\n<p>  \u0414\u0435\u043c\u043e: <a href=\"http:\/\/jsbin.com\/xituko\/edit?js,output\"><a href=\"http:\/\/jsbin.com\/xituko\/edit?js,output\">http:\/\/jsbin.com\/xituko\/edit?js,output<\/a><\/a><\/p>\n<p>  \u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432. \u041d\u043e \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0435 React \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b:<\/p>\n<pre><code class=\"javascript\">\/\/ \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u043d\u043e\u0433\u043e\u043a\u0440\u0430\u0442\u043d\u043e function rect(props) {     const {ctx, x, y, width, height} = props;     ctx.fillRect(x, y, width, height); } class CanvasComponent extends React.Component {     componentDidMount() {         this.updateCanvas();     }     componentDidUpdate() {         this.updateCanvas();     }     updateCanvas() {         const ctx = this.refs.canvas.getContext('2d');         ctx.clearRect(0,0, 300, 300);         \/\/ \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c &quot;\u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0435&quot; \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b         rect({ctx, x: 10, y: 10, width: 50, height: 50});         rect({ctx, x: 110, y: 110, width: 50, height: 50});     }     render() {          return (              &lt;canvas ref=&quot;canvas&quot; width={300} height={300}\/&gt;          );     } } ReactDOM.render(&lt;CanvasComponent\/&gt;, document.getElementById('container'));<\/code><\/pre>\n<p>  \u0410 \u0447\u0442\u043e \u043d\u0430 \u0441\u0447\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u0434\u043e\u0431\u043d\u044b\u0445 \u0440\u0435\u0430\u043a\u0442\u043e\u0432\u0441\u043a\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 (\u0442\u0430\u043a\u0438\u0435 \u043a\u0430\u043a &quot;shouldComponentUpdate&quot;, &quot;componentDidMount&quot; \u0438 \u0442.\u0434.)?<br \/>  \u0410 \u043a\u0430\u043a \u0436\u0435 \u043f\u043e\u0434\u0445\u043e\u0434 &quot;\u043f\u043e\u043b\u043d\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 render&quot;?<\/p>\n<h2>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h2>\n<p>  \u041c\u043d\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f \u0440\u0435\u0430\u043a\u0442\u043e\u0432\u0441\u043a\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u043a \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u0441\u0434\u0435\u043b\u0430\u043b \u043f\u043b\u0430\u0433\u0438\u043d <a href=\"https:\/\/github.com\/lavrton\/react-konva\">react-konva<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0438\u0441\u0443\u0435\u0442 \u043d\u0430 canvas \u0447\u0435\u0440\u0435\u0437 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a Konva. <\/p>\n<pre><code class=\"bash\">npm install react konva react-konva --save<\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435<\/p>\n<pre><code class=\"javascript\">import React from 'react'; import ReactDOM from 'react-dom'; import {Layer, Rect, Stage, Group} from \u2018react-konva\u2019;  class MyRect extends React.Component {     constructor(...args) {       super(...args);       this.state = {         color: 'green'       };       this.handleClick = this.handleClick.bind(this);     }     handleClick() {       this.setState({         color: Konva.Util.getRandomColor()       });     }     render() {         return (             &lt;Rect                 x={10} y={10} width={50} height={50}                 fill={this.state.color}                 shadowBlur={10}                 onClick={this.handleClick}             \/&gt;         );     } } function App() {     return (       &lt;Stage width={700} height={700}&gt;         &lt;Layer&gt;             &lt;MyRect\/&gt;         &lt;\/Layer&gt;       &lt;\/Stage&gt;     ); } ReactDOM.render(&lt;App\/&gt;, document.getElementById('container'));<\/code><\/pre>\n<p>  \u0414\u0435\u043c\u043e: <a href=\"http:\/\/jsbin.com\/camene\/5\/edit?html,js,output\"><a href=\"http:\/\/jsbin.com\/camene\/5\/edit?html,js,output\">http:\/\/jsbin.com\/camene\/5\/edit?html,js,output<\/a><\/a><\/p>\n<h2>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f<\/h2>\n<p>  <\/p>\n<h3>react-konva vs <a href=\"https:\/\/github.com\/Flipboard\/react-canvas\">react-canvas<\/a><\/h3>\n<p>  <a href=\"https:\/\/github.com\/Flipboard\/react-canvas\">react-canvas<\/a> \u044d\u0442\u043e \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043b\u0430\u0433\u0438\u043d. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c &quot;\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 DOM \u043e\u0431\u044a\u0435\u043a\u0442\u044b&quot; (\u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438, \u0442\u0435\u043a\u0441\u0442) \u0441 \u043e\u0447\u0435\u043d\u044c \u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e. \u041d\u043e \u044d\u0442\u043e\u0442 \u043f\u043b\u0430\u0433\u0438\u043d \u041d\u0415 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u0433\u0440\u0430\u0444\u0438\u043a\u0443. \u0412 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a <em>react-konva<\/em> \u0441\u0434\u0435\u043b\u0430\u043d \u0438\u043c\u0435\u043d\u043d\u043e \u0434\u043b\u044f \u0440\u0438\u0441\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u0433\u0440\u0430\u0444\u0438\u043a\u0438 \u043d\u0430 canvas \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e React.<\/p>\n<h3>react-konva vs <a href=\"https:\/\/github.com\/reactjs\/react-art\">react-art<\/a><\/h3>\n<p>  <a href=\"https:\/\/github.com\/reactjs\/react-art\">react-art<\/a> \u0442\u0430\u043a \u0436\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0438\u0441\u043e\u0432\u0430\u0442\u044c \u0433\u0440\u0430\u0444\u0438\u043a\u0443 \u0438 \u0438\u043c\u0435\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 SVG, \u043d\u043e \u043e\u043d \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0434\u043b\u044f \u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0444\u0438\u0433\u0443\u0440.<\/p>\n<h3>react-konva vs vanilla canvas<\/h3>\n<p>  \u041f\u0440\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0433\u043e\u0432\u043e\u0440\u044f\u0442 \u043e\u0447\u0435\u043d\u044c \u0447\u0430\u0441\u0442\u043e, \u043a\u043e\u0433\u0434\u0430 \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u044e\u0442 React. \u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u0434\u043d\u0430 \u0438\u0437 \u0433\u043b\u0430\u0432\u043d\u044b\u0445 \u043f\u0440\u0438\u0447\u0438\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f React \u2014 \u044d\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p>  \u041d\u043e \u044f \u0441\u0434\u0435\u043b\u0430\u043b \u044d\u0442\u043e\u0442 \u043f\u043b\u0430\u0433\u0438\u043d \u041d\u0415 \u0434\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e. \u041f\u0440\u044f\u043c\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 canvas \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u0443\u0442\u0451\u043c, \u0442\u0430\u043a, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <em>react-konva<\/em>, \u043c\u044b \u0438\u043c\u0435\u0435\u043c Konva, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e\u0432\u0435\u0440\u0445 canvas, \u0438 React, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e\u0432\u0435\u0440\u0445 Konva.<\/p>\n<p>  \u041d\u043e \u044f \u0441\u0434\u0435\u043b\u0430\u043b \u043f\u043b\u0430\u0433\u0438\u043d \u0434\u043b\u044f \u0431\u043e\u0440\u044c\u0431\u044b \u0441\u043e \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. Konva \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0441\u0438\u043b\u044c\u043d\u043e (\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u044b \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u043d\u0430 \u0445\u043e\u043b\u0441\u0442\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 &quot;click&quot;, \u0431\u0435\u0437 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u0442\u044f\u0436\u0435\u043b\u043e). \u041d\u043e React \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0435\u0449\u0435 \u0441\u0438\u043b\u044c\u043d\u0435\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0445\u043e\u0440\u043e\u0448\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043a\u043e\u0434\u0430 \u0438 \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<h2>\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438<\/h2>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/313\/3b8\/272\/3133b8272fd2482dbdfca6d6fad34a76.png\" alt=\"konva logo\"\/><\/p>\n<p>  <strong>react-konva<\/strong> \u0438\u043c\u0435\u0435\u0442 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u0444\u0438\u0433\u0443\u0440: Circle, Rect, Ellipse, Line, Sprite, Image, Text, TextPath, Star, Ring, Arc, Label, SVG Path, RegularPolygon, Arrow \u0438 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0435 \u0444\u0438\u0433\u0443\u0440\u044b. \u0422\u0430\u043a \u0436\u0435 \u0435\u0441\u0442\u044c \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 drag&amp;drop, \u0430\u043d\u0438\u043c\u0430\u0446\u0438\u0438, \u0444\u0438\u043b\u044c\u0442\u0440\u044b, \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043a\u044d\u0448\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u0434\u0435\u0441\u043a\u0442\u043e\u043f \u0438 \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f (mouseenter, click, dblclick, dragstart, dragmove, dragend, tap, dbltap, \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435).<\/p>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 \u043d\u0435\u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u0444\u0438\u0433\u0443\u0440\u044b<\/h3>\n<p>  <\/p>\n<pre><code class=\"javascript\">function MyShape() {   return (      &lt;Shape fill=\u201d#00D2FF\u201d draggable          sceneFunc={function (ctx) {              ctx.beginPath();              ctx.moveTo(20, 50);              ctx.lineTo(220, 80);              ctx.quadraticCurveTo(150, 100, 260, 170);              ctx.closePath();              \/\/ Konva specific method              ctx.fillStrokeShape(this);          }}      \/&gt;   ); }<\/code><\/pre>\n<p>  \u0414\u0435\u043c\u043e: <a href=\"http:\/\/jsbin.com\/gakadi\/2\/edit?html,js,output\"><a href=\"http:\/\/jsbin.com\/gakadi\/2\/edit?html,js,output\">http:\/\/jsbin.com\/gakadi\/2\/edit?html,js,output<\/a><\/a><\/p>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u043c\u0438<\/h3>\n<p>  <\/p>\n<pre><code class=\"javascript\">class MyCircle extends React.Component {     constructor(\u2026args) {         super(\u2026args);         this.state = { isMouseInside: false};         this.handleMouseEnter = this.handleMouseEnter.bind(this);         this.handleMouseLeave = this.handleMouseLeave.bind(this);     }     handleMouseEnter() {         this.setState({ isMouseInside: true});     }     handleMouseLeave() {         this.setState({ isMouseInside: false});     }     render() {         return (             &lt;Circle                 x={100} y={60} radius={50}                 fill=\u201dyellow\u201d stroke=\u201dblack\u201d                 strokeWidth={this.state.isMouseInside ? 5 : 1}                 onMouseEnter={this.handleMouseEnter}                 onMouseLeave={this.handleMouseLeave}             \/&gt;         );     } }<\/code><\/pre>\n<p>  \u0414\u0435\u043c\u043e: <a href=\"http:\/\/jsbin.com\/tekopu\/1\/edit\"><a href=\"http:\/\/jsbin.com\/tekopu\/1\/edit\">http:\/\/jsbin.com\/tekopu\/1\/edit<\/a><\/a><\/p>\n<h2>\u0421\u0441\u044b\u043b\u043a\u0438<\/h2>\n<p>  Github: <a href=\"https:\/\/github.com\/lavrton\/react-konva\"><a href=\"https:\/\/github.com\/lavrton\/react-konva\">https:\/\/github.com\/lavrton\/react-konva<\/a><\/a><br \/>  Konva framework: <a href=\"https:\/\/github.com\/lavrton\/react-konva\"><a href=\"http:\/\/konvajs.github.io\/\">http:\/\/konvajs.github.io\/<\/a><\/a>                 <\/p>\n<div class=\"clear\"><\/div>\n<p> \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\/276585\/\"> https:\/\/habrahabr.ru\/post\/276585\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u0415\u0441\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a React, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u043c \u0438 \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u043c DOM \u0432 \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u043c \u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0442\u0438\u043b\u0435. \u042d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a\u0440\u0443\u0442\u043e.<\/p>\n<p>  \u041d\u043e \u044f \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0440\u043e \u043e\u043f\u044b\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f React, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0439 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0435\u0439 \u043d\u0430\u0434 &quot;\u0438\u043c\u043c\u0443\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u044b\u043c&quot; canvas \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c. \u0417\u0432\u0443\u0447\u0438\u0442 \u0441\u0442\u0440\u0430\u043d\u043d\u043e, \u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u043d\u043e.<\/p>\n<h2>\u041c\u043e\u0442\u0438\u0432\u0430\u0446\u0438\u044f<\/h2>\n<p>  \u042f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u044d\u043b\u0435\u043c\u0435\u043d\u0442 <code>&lt;canvas&gt;<\/code> \u043e\u0447\u0435\u043d\u044c \u0447\u0430\u0441\u0442\u043e. \u042f \u0441\u0434\u0435\u043b\u0430\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0432\u0435\u0431-\u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 canvas \u2014 \u044d\u0442\u043e \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c canvas \u0431\u0435\u0437 \u0432\u0441\u044f\u043a\u0438\u0445 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u043e\u0432 \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u043e \u0432 \u043a\u0440\u0443\u043f\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u044f \u043d\u0430\u0447\u0430\u043b \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438. \u0421\u0435\u0439\u0447\u0430\u0441 \u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a <a href=\"http:\/\/konvajs.github.io\/\">Konva<\/a> (\u0435\u0441\u0442\u044c \u043e\u0431\u0437\u043e\u0440\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f <a href=\"https:\/\/habrahabr.ru\/post\/250897\/\"><a href=\"https:\/\/habrahabr.ru\/post\/250897\/\">https:\/\/habrahabr.ru\/post\/250897\/<\/a><\/a>).<\/p>\n<p>  Konva \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043e\u0447\u0435\u043d\u044c \u0441\u0438\u043b\u044c\u043d\u043e, \u043d\u043e \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0435\u0433\u043e. \u0422\u0430\u043a \u0436\u0435 \u044f \u043d\u0430\u0447\u0430\u043b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c React \u0432 \u0441\u0432\u043e\u0438\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445, \u0438 \u043e\u043d \u043c\u043d\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0440\u0430\u0432\u0438\u0442\u0441\u044f. \u0418 \u044f \u043f\u043e\u0434\u0443\u043c\u0430\u043b, \u043a\u0430\u043a \u0436\u0435 \u044f \u043c\u043e\u0433\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c React \u0434\u043b\u044f \u0440\u0438\u0441\u043e\u0432\u0430\u043d\u0438\u044f \u0433\u0440\u0430\u0444\u0438\u043a\u0438 \u043d\u0430 canvas?<\/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-273702","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/273702","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=273702"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/273702\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=273702"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=273702"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=273702"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}