<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Seyyed Morteza Moosavi</title>
    <description>The latest articles on DEV Community by Seyyed Morteza Moosavi (@smmoosavi).</description>
    <link>https://dev.to/smmoosavi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F461782%2F25a10184-3d1c-4e9e-ae34-47755b68a6a3.jpeg</url>
      <title>DEV Community: Seyyed Morteza Moosavi</title>
      <link>https://dev.to/smmoosavi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/smmoosavi"/>
    <language>en</language>
    <item>
      <title>React Wire basic concepts</title>
      <dc:creator>Seyyed Morteza Moosavi</dc:creator>
      <pubDate>Tue, 29 Sep 2020 08:13:49 +0000</pubDate>
      <link>https://dev.to/smmoosavi/react-wire-basic-concepts-492p</link>
      <guid>https://dev.to/smmoosavi/react-wire-basic-concepts-492p</guid>
      <description>&lt;p&gt;In this post, we will cover the &lt;code&gt;@forminator/react-wire&lt;/code&gt; basic concepts.&lt;/p&gt;

&lt;h1&gt;
  
  
  Wire
&lt;/h1&gt;

&lt;p&gt;A wire is an object that contained a value inside it.&lt;/p&gt;

&lt;h1&gt;
  
  
  Create a new wire
&lt;/h1&gt;

&lt;p&gt;The &lt;code&gt;userWire&lt;/code&gt; hook, returns a new wire.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;wire&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useWire&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;initialValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Or you can connect the wire to another wire, called an up-link wire. The value of both wires will be synced all the time.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;wire&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useWire&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;anotherWire&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Reading the wire value
&lt;/h1&gt;

&lt;p&gt;The &lt;code&gt;useWireValue&lt;/code&gt; returns the current value of the wire, and rerender component when the wire value changed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useWireValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;wire&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Changing wire value
&lt;/h1&gt;

&lt;p&gt;The &lt;code&gt;useWireState&lt;/code&gt; returns &lt;code&gt;value&lt;/code&gt; and &lt;code&gt;setValue&lt;/code&gt;. exactly same as default &lt;code&gt;useState&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setValue&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useWireState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;initialValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;You can also pass a wire to the first argument, and the returned value will be synced with the wire.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight tsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setValue&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;useWireState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;wire&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;initialValue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>react</category>
      <category>typescript</category>
      <category>reactwire</category>
      <category>webdev</category>
    </item>
    <item>
      <title>React Wire</title>
      <dc:creator>Seyyed Morteza Moosavi</dc:creator>
      <pubDate>Wed, 02 Sep 2020 09:52:45 +0000</pubDate>
      <link>https://dev.to/smmoosavi/react-wire-77h</link>
      <guid>https://dev.to/smmoosavi/react-wire-77h</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;connect react components with wire&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The &lt;code&gt;react-wire&lt;/code&gt; lib helps to develop a cleaner app, easy controlled/uncontrolled components, and beyond.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add @forminator/react-wire
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/forminator/react-wire"&gt;repo&lt;/a&gt;, &lt;a href="https://www.npmjs.com/package/@forminator/react-wire"&gt;npm&lt;/a&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>typescript</category>
      <category>reactwire</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
