<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=416195&amp;view=findpost&amp;p=3814528</guid>
        <pubDate>Sat, 09 Nov 2019 03:28:10 +0000</pubDate>
        <title>React.render</title>
        <link>https://forum.sources.ru/index.php?showtopic=416195&amp;view=findpost&amp;p=3814528</link>
        <description><![CDATA[Cfon: Сорян все оказалось намного проще чем я тут развел&#33;  :lool:  <br>
<br>
Как всегда все оказалось просто :D  <br>
Наш функциональный компонент и есть метод render компонента&#33; К чему я это веду? <br>
Все дело в том что наш внутренний компонент Output на каждой отрисовке создается снова и поэтому реакт полностью его отрисовывает при каждом рендеринге. Логично? :D<br>
<br>
Есть нюансы например что если перенести стейт внутрь Output? <br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">const Timer = () =&#62; {</div><div class="code_line">&nbsp;&nbsp; &nbsp;const Output = () =&#62; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;const [state, setState] = React.useState({</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;time: getCurrentTime(),</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;});</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;React.useEffect(() =&#62; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const id = setInterval(() =&#62; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setState({ time: getCurrentTime() });</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}, 1000);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return () =&#62; clearInterval(id);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;}, []);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return (</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;div className=&quot;output&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;h2&#62;It is {state.time}&#60;/h2&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;/div&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;);</div><div class="code_line">&nbsp;&nbsp; &nbsp;};</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;return (</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;div className=&quot;timer&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;h1&#62;Hello, World!&#60;/h1&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;Output /&#62; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;/div&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;);</div><div class="code_line">};</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script><br>
Теперь все пучком в Output перерисовывается тока {state.time} те даже при том что определение компоненты занова перезаписывается тем не менее реакт определяет тока нужные изменения.]]></description>
        <author>Cfon</author>
        <category>JavaScript, DOM/DHTML</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=416195&amp;view=findpost&amp;p=3814373</guid>
        <pubDate>Thu, 07 Nov 2019 12:08:43 +0000</pubDate>
        <title>React.render</title>
        <link>https://forum.sources.ru/index.php?showtopic=416195&amp;view=findpost&amp;p=3814373</link>
        <description><![CDATA[Cfon: Давайте изучим этот перл <br>Кстати этот пример можно изи юзать как шаблон для фастовой проверки кода при изучении реакт. <br>Итак по строчно :D <br>1 getCurrentTime - функция возвращает текущее время<br>2 Далее идет определение функционального компонента Timer<br>3 инициализация стейта где сохраняет текущее время<br>4 инициализация эффекта в данном случае он имитирует componentDidMount и запускает таймет каждые 1000мс, возвращаемая функция иммитирует componentWillUnmount и отключает таймер<br>5 Далее наш предмет изучения определение функционального компонента Output<br>Он возвращает разметку в которой выводится текущее время.  <br>6 Возврат разметки где выводится заголовок с Хело ворлд для того чтобы проще различать рендеринг внутренней разметки и внешней. Ну и далее выводится сам наш компонент Output, в виде реакт-элемента и в виде вызова функции (я его закомментировал)<br><br>Напомню тема такая наш Output в случае разметки при обновлении стейта полностью перерисовывается, т.е и заголовок Хелло Ворлд и текущее время, а в случае вызова функции (второй вариант) перерисовывается тока текущее время и это правильно. <br><br>Все пока  :D]]></description>
        <author>Cfon</author>
        <category>JavaScript, DOM/DHTML</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=416195&amp;view=findpost&amp;p=3814288</guid>
        <pubDate>Thu, 07 Nov 2019 07:16:28 +0000</pubDate>
        <title>React.render</title>
        <link>https://forum.sources.ru/index.php?showtopic=416195&amp;view=findpost&amp;p=3814288</link>
        <description><![CDATA[Cfon: Зерте простой пример, запускайте сразу в броузере и инспектируйте разметку  :D <br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">&#60;!DOCTYPE html&#62;</div><div class="code_line">&#60;html lang=&quot;en&quot;&#62;</div><div class="code_line">&#60;head&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;meta charset=&quot;UTF-8&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;ie=edge&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;title&#62;React Render Bug?&#60;/title&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;script src=&quot;https://unpkg.com/react@16/umd/react.production.min.js&quot;&#62;&#60;/script&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;script src=&quot;https://unpkg.com/react-dom@16/umd/react-dom.production.min.js&quot;&#62;&#60;/script&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;script src=&quot;https://unpkg.com/babel-standalone@6.26.0/babel.min.js&quot;&#62;&#60;/script&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;script src=&quot;https://unpkg.com/moment@2.24.0/min/moment.min.js&quot;&#62;&#60;/script&#62;</div><div class="code_line">&#60;/head&#62;</div><div class="code_line">&#60;body&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;div id=&quot;root&quot;&#62;&#60;/div&#62;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;script type=&quot;text/babel&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;const getCurrentTime = () =&#62; moment().format(&#39;hh:mm:ss A.&#39;);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;const Timer = () =&#62; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const [state, setState] = React.useState({</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;time: getCurrentTime(),</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;});</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;React.useEffect(() =&#62; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const id = setInterval(() =&#62; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setState({ time: getCurrentTime() });</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}, 1000);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return () =&#62; clearInterval(id);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}, []);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const Output = () =&#62; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return (</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;div className=&quot;output&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;h2&#62;It is {state.time}&#60;/h2&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;/div&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;};</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return (</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;div className=&quot;timer&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;h1&#62;Hello, World!&#60;/h1&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;Output /&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{/*{Output()}*/}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;/div&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;};</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;ReactDOM.render(&#60;Timer /&#62;, document.querySelector(&#39;#root&#39;))</div><div class="code_line">&nbsp;&nbsp; &nbsp;&#60;/script&#62;</div><div class="code_line">&#60;/body&#62;</div><div class="code_line">&#60;/html&#62;</div></ol></div></div></div></div><br>
Мой комменты апосля  :D]]></description>
        <author>Cfon</author>
        <category>JavaScript, DOM/DHTML</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=416195&amp;view=findpost&amp;p=3814248</guid>
        <pubDate>Wed, 06 Nov 2019 18:46:02 +0000</pubDate>
        <title>React.render</title>
        <link>https://forum.sources.ru/index.php?showtopic=416195&amp;view=findpost&amp;p=3814248</link>
        <description><![CDATA[Cfon: Разобрался&#33; :D <br><br>Если коротко, то в случае формы тэга &lt;Table /&gt; реакт создает реакт-элемент, который полностью отрисовывается, поскольку изменяется состояние внешнего компонента DataTable, а у компонента Table нет состояния. <br>В случае выражения вызова функции {Table()} реакт-элемент не создается, а возвращаются внутренние реакт-элементы представляющие компонент Table и они становятся частью компонента DataTable, и когда изменяется состояние, то реакт-дом может определить только те части компонента которые требуют перерисовки  :blush:<br><br>Более подробно я опишу позже на более простом примером чем тот что на гите :D]]></description>
        <author>Cfon</author>
        <category>JavaScript, DOM/DHTML</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=416195&amp;view=findpost&amp;p=3814025</guid>
        <pubDate>Mon, 04 Nov 2019 11:39:32 +0000</pubDate>
        <title>React.render</title>
        <link>https://forum.sources.ru/index.php?showtopic=416195&amp;view=findpost&amp;p=3814025</link>
        <description><![CDATA[Cfon: - Маста, а как сделать глубокую копию?  :huh: <br>
<br>
Новичок на самом деле глубокую копию делать надо не всегда. Все зависит от глубины изменяемых данных :D <br>
<br>
- Это как?  :scratch: <br>
<br>
Например, вот как правильно скопировать данные в функции updateCell (см комменты)<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">const updateCell = value =&#62; {</div><div class="code_line">&nbsp;&nbsp; &nbsp;const { rowIndex: i, cellIndex: k } = _edit;</div><div class="code_line">&nbsp;&nbsp; &nbsp;const dataCopy = [..._data];</div><div class="code_line">&nbsp;&nbsp; &nbsp;const rowCopy = [..._data[i]]; // копируем внутренний массив ячеек</div><div class="code_line">&nbsp;&nbsp; &nbsp;rowCopy[k] = value; // изменяем значение в ячейке</div><div class="code_line">&nbsp;&nbsp; &nbsp;dataCopy[i] = rowCopy; // присваиваем массив измененых ячеек копии главного массива</div><div class="code_line">&nbsp;&nbsp; &nbsp;setData(dataCopy);</div><div class="code_line">&nbsp;&nbsp; &nbsp;setEdit({ rowIndex: null, cellIndex: null });</div><div class="code_line">};</div></ol></div></div></div></div><br>
Есть более красивый способ это сделать с помощью линз Ramda  <br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">const updateCell = value =&#62; {</div><div class="code_line">&nbsp;&nbsp; &nbsp;const { rowIndex: i, cellIndex: k } = _edit;</div><div class="code_line">&nbsp;&nbsp; &nbsp;const cellLens = R.lensPath([i, k]);</div><div class="code_line">&nbsp;&nbsp; &nbsp;const dataCopy = R.set(cellLens, value, _data);</div><div class="code_line">&nbsp;&nbsp; &nbsp;setData(dataCopy);</div><div class="code_line">&nbsp;&nbsp; &nbsp;setEdit({ rowIndex: null, cellIndex: null });</div><div class="code_line">};</div></ol></div></div></div></div><br>
Ну или с помощью Immer или Immutable  :D]]></description>
        <author>Cfon</author>
        <category>JavaScript, DOM/DHTML</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=416195&amp;view=findpost&amp;p=3814014</guid>
        <pubDate>Mon, 04 Nov 2019 08:13:13 +0000</pubDate>
        <title>React.render</title>
        <link>https://forum.sources.ru/index.php?showtopic=416195&amp;view=findpost&amp;p=3814014</link>
        <description><![CDATA[Cfon: Пока думал о текущей трабле обнаружил с коде другую грубейшую ошибку  :D<br>
<br>
Я неправильно делал копию данных _data&#33; <br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">const dataCopy = [..._data];</div></ol></div></div></div></div><br>
Тут создается неглубокая копия, а следовательно в функциях handleSort и updateCell данные изменялись непосредствено через _data.]]></description>
        <author>Cfon</author>
        <category>JavaScript, DOM/DHTML</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=416195&amp;view=findpost&amp;p=3813846</guid>
        <pubDate>Wed, 30 Oct 2019 15:49:30 +0000</pubDate>
        <title>React.render</title>
        <link>https://forum.sources.ru/index.php?showtopic=416195&amp;view=findpost&amp;p=3813846</link>
        <description><![CDATA[Cfon: Никто не знает сам автор реакта не ведает сказал что будет думать :D<br>Конкретно я озадачил реакт сообщество уже кирпичами какают :lool:]]></description>
        <author>Cfon</author>
        <category>JavaScript, DOM/DHTML</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=416195&amp;view=findpost&amp;p=3813694</guid>
        <pubDate>Tue, 29 Oct 2019 13:01:27 +0000</pubDate>
        <title>React.render</title>
        <link>https://forum.sources.ru/index.php?showtopic=416195&amp;view=findpost&amp;p=3813694</link>
        <description><![CDATA[Cfon: Если вынести Table в отдельную компоненту то все пучком апдейтится 1 ячейка<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">import { Table } from &#39;./Table&#39;;</div><div class="code_line">&nbsp;</div><div class="code_line">export const DataTable = props =&#62; {</div><div class="code_line">&nbsp;&nbsp; &nbsp;...</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;const { headers } = props;</div><div class="code_line">&nbsp;&nbsp; &nbsp;return (</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;div&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;Table</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;headers={headers}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;handleSort={handleSort}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_sort={_sort}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;handleShowEditor={handleShowEditor}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_data={_data}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_edit={_edit}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;updateCell={updateCell}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;/div&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;);</div><div class="code_line">};</div></ol></div></div></div></div>]]></description>
        <author>Cfon</author>
        <category>JavaScript, DOM/DHTML</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=416195&amp;view=findpost&amp;p=3813678</guid>
        <pubDate>Tue, 29 Oct 2019 10:59:15 +0000</pubDate>
        <title>React.render</title>
        <link>https://forum.sources.ru/index.php?showtopic=416195&amp;view=findpost&amp;p=3813678</link>
        <description><![CDATA[Cfon: Доброго времени суток <br>
<br>
Столкнулся с одним непонятным мне поведением отрисовки компоненты. В моем примере есть компонента DataTable, в ней можно редактировать содержимое каждой ячейки таблицы, ниже приведен кусок кода (полный пример см на <a class='tag-url' href='https://github.com/Cfon/react-render-bug' target='_blank'><em class='tag-i'>https://github.com/Cfon/react-render-bug</em></a>). Так вот если вызвать внутрений компонент Table, как функцию в разметке(см в самом конце кода я отметил в коментарии), то если изменить данные в ячейке, то реакт обновляет тока редактируемую ячейку. А вот если вызвать компонент как тэг в разметке и попробовать редактировать данные, то обновляется вся таблица&#33;  :wacko: <br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">import React, { useState } from &#39;react&#39;;</div><div class="code_line">import * as PropTypes from &#39;prop-types&#39;;</div><div class="code_line">import { ArrowDown, ArrowUp, NoArrow } from &#39;./Arrows&#39;;</div><div class="code_line">import { Editor } from &#39;./Editor&#39;;</div><div class="code_line">&nbsp;</div><div class="code_line">export const DataTable = props =&#62; {</div><div class="code_line">&nbsp;&nbsp; &nbsp;const [_data, setData] = useState(props.initialData);</div><div class="code_line">&nbsp;&nbsp; &nbsp;const [_sort, setSort] = useState({</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;sortBy: null,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;desc: false,</div><div class="code_line">&nbsp;&nbsp; &nbsp;});</div><div class="code_line">&nbsp;&nbsp; &nbsp;const [_edit, setEdit] = useState(null);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;const handleSort = event =&#62; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;const index = event.target.cellIndex;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;const { sortBy, desc } = _sort;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;const descending = sortBy === index &amp;&amp; !desc;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;const dataCopy = [..._data];</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;dataCopy.sort((a, b) =&#62; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return descending</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;? a[index] &#60; b[index]</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;? 1</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: -1</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: a[index] &#62; b[index]</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;? 1</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: -1;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;});</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;setData(dataCopy);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;setSort({</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sortBy: index,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;desc: descending,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;});</div><div class="code_line">&nbsp;&nbsp; &nbsp;};</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;const handleShowEditor = event =&#62; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;setEdit({</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;row: parseInt(event.target.dataset.row),</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cell: event.target.cellIndex,</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;});</div><div class="code_line">&nbsp;&nbsp; &nbsp;};</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;const updateCell = value =&#62; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;const { row, cell } = _edit;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;const dataCopy = [..._data];</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;dataCopy[row][cell] = value;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;setData(dataCopy);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;setEdit(null);</div><div class="code_line">&nbsp;&nbsp; &nbsp;};</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;const { headers } = props;</div><div class="code_line">&nbsp;&nbsp; &nbsp;const Table = () =&#62; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;return (</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;table className=&quot;table table-dark&quot;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;thead onClick={handleSort}&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;tr&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{headers.map((title, index) =&#62; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const { sortBy, desc } = _sort;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return (</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;th key={index}&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{sortBy === index ? (</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;desc ? (</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;ArrowUp /&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;) : (</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;ArrowDown /&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;) : (</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;NoArrow /&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;)}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{title}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;/th&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;})}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;/tr&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;/thead&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;tbody onDoubleClick={handleShowEditor}&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{_data.map((row, rowIndex) =&#62; (</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;tr key={rowIndex}&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{row.map((cell, cellIndex) =&#62; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return (</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;td key={cell} data-row={rowIndex}&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{_edit &amp;&amp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_edit.row === rowIndex &amp;&amp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;_edit.cell === cellIndex ? (</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;Editor</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cell={cell}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;update={updateCell}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;/&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;) : (</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cell</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;)}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;/td&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;})}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;/tr&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;))}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;/tbody&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;/table&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;);</div><div class="code_line">&nbsp;&nbsp; &nbsp;};</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;return (</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;div&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{/* - либо как разметка ---- */}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{/*&#60;Table /&#62;*/} </div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{/* - либо как выражение ---- */}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{Table()}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&#60;/div&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp;);</div><div class="code_line">};</div><div class="code_line">&nbsp;</div><div class="code_line">DataTable.propTypes = {</div><div class="code_line">&nbsp;&nbsp; &nbsp;initData: PropTypes.arrayOf(PropTypes.string),</div><div class="code_line">};</div><div class="code_line">&nbsp;</div><div class="code_line">DataTable.defaultProps = {</div><div class="code_line">&nbsp;&nbsp; &nbsp;initialData: [],</div><div class="code_line">};</div></ol></div></div></div></div><br>
Короче либо я чего то не даганяю либо это баг реакта  :wall:]]></description>
        <author>Cfon</author>
        <category>JavaScript, DOM/DHTML</category>
      </item>
	
      </channel>
      </rss>
	