<?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=416320&amp;view=findpost&amp;p=3814687</guid>
        <pubDate>Wed, 13 Nov 2019 05:01:17 +0000</pubDate>
        <title>React хуки</title>
        <link>https://forum.sources.ru/index.php?showtopic=416320&amp;view=findpost&amp;p=3814687</link>
        <description><![CDATA[Cfon: Разобралси решение не скажу мучайтесь  :lool:]]></description>
        <author>Cfon</author>
        <category>JavaScript, DOM/DHTML</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=416320&amp;view=findpost&amp;p=3814618</guid>
        <pubDate>Tue, 12 Nov 2019 05:56:19 +0000</pubDate>
        <title>React хуки</title>
        <link>https://forum.sources.ru/index.php?showtopic=416320&amp;view=findpost&amp;p=3814618</link>
        <description><![CDATA[Cfon: Ну вот нашел очередной косяк, значит пишу<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 Rating = props =&#62; {</div><div class="code_line">&nbsp;&nbsp; &nbsp;const [rating, setRating] = React.useState(props.defaultValue);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;React.useEffect(() =&#62; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;props.onRating(rating);</div><div class="code_line">&nbsp;&nbsp; &nbsp;}, [rating]);</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;{new Array(props.max).fill(0).map((_, index) =&#62; (</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;span</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;key={index}</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;onClick={</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;!props.readonly ? setRating.bind(null, index + 1) : null</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;&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{index &#60; rating ? (</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;Star disable={props.readonly} /&#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; &nbsp; &nbsp; &nbsp; &nbsp;&#60;UnfilledStar disable={props.readonly} /&#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;/span&#62;</div><div class="code_line">&nbsp;&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><div class="code_line">&nbsp;</div><div class="code_line">const App = () =&#62; {</div><div class="code_line">&nbsp;&nbsp; &nbsp;const handleRating = rating =&#62; {</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;console.log(rating);</div><div class="code_line">&nbsp;&nbsp; &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;&#60;p&#62;Rating&#60;/p&#62;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#60;Rating defaultValue={3} onRating={handleRating} /&#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><div class="code_line">&nbsp;</div><div class="code_line">ReactDOM.render(&#60;App /&#62;, document.querySelector(&#39;#root&#39;));</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script><br>
полное демо смотри на гите<br>
<a class='tag-url' href='https://github.com/Cfon/react-hooks-warning.git' target='_blank'><em class='tag-i'>https://github.com/Cfon/react-hooks-warning.git</em></a><br>
<br>
Значит жму на звезду все работает но на консоль кроме рейтинга выводит еще и какой то малопонятный ворнинг  :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">Warning: State updates from the useState() and useReducer() Hooks don&#39;t support the second callback argument. To execute a side effect after rendering, declare it in the component body with useEffect().</div></ol></div></div></div></div>]]></description>
        <author>Cfon</author>
        <category>JavaScript, DOM/DHTML</category>
      </item>
	
      </channel>
      </rss>
	