<?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: Francis Vila</title>
    <description>The latest articles on DEV Community by Francis Vila (@francisvila).</description>
    <link>https://dev.to/francisvila</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%2F406718%2F51a6bff8-2a96-4405-82c2-77d68570906f.png</url>
      <title>DEV Community: Francis Vila</title>
      <link>https://dev.to/francisvila</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/francisvila"/>
    <language>en</language>
    <item>
      <title>Suggestion for new syntax of React reducers + context</title>
      <dc:creator>Francis Vila</dc:creator>
      <pubDate>Tue, 12 Mar 2024 11:05:33 +0000</pubDate>
      <link>https://dev.to/francisvila/suggestion-for-new-syntax-of-react-reducers-context-2ill</link>
      <guid>https://dev.to/francisvila/suggestion-for-new-syntax-of-react-reducers-context-2ill</guid>
      <description>&lt;p&gt;The suggestion is this &lt;a href="https://codesandbox.io/p/sandbox/suggestion-for-new-syntax-of-reducers-context-3ccdxl?file=%2FREADME.md"&gt;codesandbox&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I was impressed by the example suggested in &lt;a href="https://react.dev/learn/scaling-up-with-reducer-and-context"&gt;Scaling Up with Reducer and Context&lt;/a&gt;. I spent some time understanding it, and had an idea that the advantages of this technique would justify offering a simpler way of achieving it. Seeing that the React team spectacularly simplified the syntax of function components as compared to the Component class, I hope this is in the spirit of what they are striving to achieve.&lt;/p&gt;

&lt;p&gt;The example presented here is forked and edited from the example presented in &lt;a href="https://react.dev/learn/scaling-up-with-reducer-and-context"&gt;Scaling Up with Reducer and Context&lt;/a&gt;. The syntax suggested  here would, if implemented, produce the same effect. &lt;/p&gt;

&lt;p&gt;Obviously, the code presented here does not currently  function correctly.&lt;/p&gt;

&lt;p&gt;The suggestion involves:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;one new hook, named &lt;em&gt;useContextReducer&lt;/em&gt; in the example. It combines the effect of useReducer and useContext.&lt;/li&gt;
&lt;li&gt;a function to retrieve the state from the parent component, named &lt;em&gt;fetchContextReducer&lt;/em&gt; in the example.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I see several advantages to this approach:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;less code:  the file TaskContext.js from the previous example becomes redundant.&lt;/li&gt;
&lt;li&gt;code is closer to where it is used: namely in the handlers of the components that trigger them, rather than abstracted via dispatchers, type, etc.&lt;/li&gt;
&lt;li&gt;syntax is similar to that of useState, making it more familiar for entry-level React developers&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>hooks</category>
      <category>syntax</category>
    </item>
    <item>
      <title>Why the .current in useRef variables?</title>
      <dc:creator>Francis Vila</dc:creator>
      <pubDate>Tue, 28 Jun 2022 07:14:29 +0000</pubDate>
      <link>https://dev.to/francisvila/why-the-current-in-useref-variables-3h27</link>
      <guid>https://dev.to/francisvila/why-the-current-in-useref-variables-3h27</guid>
      <description>&lt;p&gt;When you declare a useState variable like this:&lt;br&gt;
&lt;code&gt;const [stateTitle, stateTitle_set] = useState('Hello State World!');&lt;/code&gt;&lt;br&gt;
when you need to use it, in JSX for example, you just enter the name of the variable.&lt;br&gt;
&lt;code&gt;&amp;lt;h1&amp;gt;{stateTitle}&amp;lt;/h1&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;But when you declare a useRef variable like this:&lt;br&gt;
&lt;code&gt;const refTitle=useRef("Hello Ref World!");&lt;/code&gt;&lt;br&gt;
every time you use that variable, you have to add in the &lt;code&gt;.current&lt;/code&gt; suffix.&lt;br&gt;
&lt;code&gt;&amp;lt;h1&amp;gt;{refTitle.current}&amp;lt;/h1&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I don't see how it is possible to use the name of the reference variable &lt;em&gt;without&lt;/em&gt; the &lt;code&gt;.current&lt;/code&gt; suffix. And the &lt;code&gt;.current&lt;/code&gt; is the only suffix I see suggested by intellisense, so I don't see what other suffix might replace it. &lt;/p&gt;

&lt;p&gt;In conclusion, I don't see why React can't just understand that &lt;code&gt;refTitle&lt;/code&gt; means &lt;code&gt;refTitle.current&lt;/code&gt;. Why you can't just write:&lt;br&gt;
&lt;code&gt;&amp;lt;h1&amp;gt;{refTitle}&amp;lt;/h1&amp;gt;&lt;/code&gt;&lt;/p&gt;

</description>
      <category>react</category>
    </item>
  </channel>
</rss>
