<?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: Gary Menzel</title>
    <description>The latest articles on DEV Community by Gary Menzel (@garymenzel).</description>
    <link>https://dev.to/garymenzel</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%2F471799%2F68173d6a-d143-4422-be79-7379a9851a8a.jpeg</url>
      <title>DEV Community: Gary Menzel</title>
      <link>https://dev.to/garymenzel</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/garymenzel"/>
    <language>en</language>
    <item>
      <title>NodeJS and "crypto" for tokens</title>
      <dc:creator>Gary Menzel</dc:creator>
      <pubDate>Wed, 13 Mar 2024 00:45:48 +0000</pubDate>
      <link>https://dev.to/garymenzel/nodejs-and-crypto-for-tokens-294a</link>
      <guid>https://dev.to/garymenzel/nodejs-and-crypto-for-tokens-294a</guid>
      <description>&lt;p&gt;If you want to have secure tokens in your action emails that can contain state information then consider using nodejs crypto functions - specifically &lt;code&gt;json-crypto&lt;/code&gt; (which is based on the crypto library).&lt;/p&gt;

&lt;p&gt;Here are the reasons why:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;URL safe (so you can use them immediately in your email links)&lt;/li&gt;
&lt;li&gt;"nonce" based - meaning that each invocation of the encryption function produces a completely different encrypted string (so it is harder to crack)&lt;/li&gt;
&lt;li&gt;easy to use with your own TOKEN secret (the thing that you protect on your backend that allows the magic to happen)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I wont go into a tutorial because the github repo for &lt;code&gt;json-crypto&lt;/code&gt; is easy to follow.&lt;/p&gt;

&lt;p&gt;The only thing I will point out is that you don't want to create your TOKEN key/secret each time - you should create that once and store it securely for your application to use it.  This is often in environment variables but you could also use a secrets vault of some kind.&lt;/p&gt;

&lt;p&gt;The other thing to consider is what you put in your payload - the JSON data that you encrypt.  I'd recommend at least a &lt;code&gt;timestamp&lt;/code&gt; of some kind (probably just the numeric date from &lt;code&gt;new Date()&lt;/code&gt;).  With a timestamp you can manage an &lt;code&gt;expiry&lt;/code&gt; of the token as well as provide timeline reporting (like how long did it take to get a response).  You also want some context regarding what is in the decrypted token.  This could be anything like a &lt;code&gt;type&lt;/code&gt; or an &lt;code&gt;email&lt;/code&gt; or both - or just some other pieces of context that allow the token to be actioned for the specific purpose you want it for (e.g. a subscription confirmation).  The payload can be any valid stringified JSON.&lt;/p&gt;

&lt;p&gt;Personally, to keep my token smaller, I like to use an array rather than an object.  The array then has a standard sequence of information like a &lt;code&gt;type&lt;/code&gt;, the &lt;code&gt;timestamp&lt;/code&gt;, a &lt;code&gt;version&lt;/code&gt;, then other context information applicable to the &lt;code&gt;type&lt;/code&gt; based on the &lt;code&gt;version&lt;/code&gt;.  But you do you - just make sure you follow a standard that you set.&lt;/p&gt;

&lt;p&gt;That's about it... Yes - no code on this one again.  I don't want to tackle the JS vs TS debate.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Thoughts about "keys" on React lists</title>
      <dc:creator>Gary Menzel</dc:creator>
      <pubDate>Wed, 06 Mar 2024 02:53:27 +0000</pubDate>
      <link>https://dev.to/garymenzel/thoughts-about-keys-on-react-lists-14bc</link>
      <guid>https://dev.to/garymenzel/thoughts-about-keys-on-react-lists-14bc</guid>
      <description>&lt;p&gt;It's been a while... a LONG while....&lt;/p&gt;

&lt;p&gt;This is a really short post about the &lt;code&gt;key&lt;/code&gt; property on React components that are lists (i.e. arrays)...&lt;/p&gt;

&lt;p&gt;I really like to get rid of all the React warnings about unique keys on lists.  You really want everything to have a unique key when it is part of a list so that things update reliably.&lt;/p&gt;

&lt;p&gt;But when you get the warnings sometimes it can be difficult to work out which component in which list is the offender.&lt;/p&gt;

&lt;p&gt;What I have found useful is to search anywhere you are using iterators (like &lt;code&gt;map&lt;/code&gt; or &lt;code&gt;reduce&lt;/code&gt;) and make sure you are composing a unique key on any component the iterator might return.&lt;/p&gt;

&lt;p&gt;The other place to look is for any &lt;code&gt;.push&lt;/code&gt; calls that might be creating the array with a component as the thing you are pushing and make sure they have unique keys.&lt;/p&gt;

&lt;p&gt;Generally, I compose the &lt;code&gt;key&lt;/code&gt; from part of the data and an index from the iterator.  If that is not unique enough, then I might also add a prefix or suffix to the &lt;code&gt;key&lt;/code&gt; as well.&lt;/p&gt;

&lt;p&gt;I like my keys to have a reasonably consistent format to them and separate sections of the &lt;code&gt;key&lt;/code&gt; with a dash (hyphen).&lt;/p&gt;

&lt;p&gt;Doing this should ensure you have consistent key generation and keep the keys all unique.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Transformer - not a robot in disguise</title>
      <dc:creator>Gary Menzel</dc:creator>
      <pubDate>Sun, 25 Oct 2020 01:37:54 +0000</pubDate>
      <link>https://dev.to/garymenzel/transformer-not-a-robot-in-disguise-30ob</link>
      <guid>https://dev.to/garymenzel/transformer-not-a-robot-in-disguise-30ob</guid>
      <description>&lt;p&gt;My job keeps me very busy and I don't get a chance to write as much about what I am doing (compared to actually doing it).  So this post is an interlude from the other series I started on pluggable APIs.&lt;/p&gt;

&lt;p&gt;The company I work for does a lot of work with data and prepares all sorts of tables and charts.  An internal project we are looking at as a need to be able to replicate these charts in a more "live" dashboard style of presentation.&lt;/p&gt;

&lt;h1&gt;
  
  
  Inspiration
&lt;/h1&gt;

&lt;p&gt;I work a lot with MongoDB and have been intrigued with how the JSON query language they have developed provides a lot of power without being being to actual procedural code.  Sometimes, you need that kind of power and flexibility after you have left the database behind and are in plain JavaScript land.  So I started wondering about how this could be done.&lt;/p&gt;

&lt;p&gt;I did look at JS modules that mimic the MongoDB approach but I wanted something that might be a little more "consumable" by developers with different language skills.&lt;/p&gt;

&lt;p&gt;But, I am probably getting ahead of myself and we should talk about what a data pipeline is first.&lt;/p&gt;

&lt;h1&gt;
  
  
  Collection Pipelines
&lt;/h1&gt;

&lt;p&gt;Martin Fowler describes &lt;a href="https://martinfowler.com/articles/collection-pipeline/"&gt;Collection Pipelines&lt;/a&gt; as follows:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Collection pipelines are a programming pattern where you organize some computation as a sequence of operations which compose by taking a collection as output of one operation and feeding it into the next.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So it is a bit like this....&lt;/p&gt;

&lt;p&gt;collection =&amp;gt; function =&amp;gt; output =&amp;gt; function =&amp;gt; ......&lt;/p&gt;

&lt;p&gt;One of the ways we can do this in JavaScript is with a &lt;code&gt;Promise&lt;/code&gt;.  Promises can have an initial state and can pass the output of one operation into the next via the &lt;code&gt;.then&lt;/code&gt; chaining function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;someData&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// do something here&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newResult&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="c1"&gt;// details omitted&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;newResult&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;previousResult&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="c1"&gt;// something else&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;NOTE&lt;/em&gt;: The above example is pseudocode and Promises can also come in the async/wait flavour. The importance of the particular choice for the example will become apparent soon.&lt;/p&gt;

&lt;p&gt;This mechanism is great, but it means we have to know when we write the code what each of the operations are.&lt;/p&gt;

&lt;p&gt;If we look at Martin Fowler's description, one thing that stands out is the word &lt;code&gt;sequence&lt;/code&gt;.  The main mechanism in JavaScript for a &lt;code&gt;sequence&lt;/code&gt; is an &lt;code&gt;array&lt;/code&gt;.  What if we could use an array to give us the sequence we need but also leverage the power of the Promise/then pattern?&lt;/p&gt;

&lt;h1&gt;
  
  
  Combining Promises and Reduce
&lt;/h1&gt;

&lt;p&gt;As it just so happens, someone has already thought about this and over on the MDN site there is an article that includes the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;func1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;func2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;func3&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result3&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="cm"&gt;/* use result3 */&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will have to scroll down to the Composition section to &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises"&gt;find it&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We can make a nice &lt;code&gt;sequence&lt;/code&gt; function to abstract this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sequence&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;operations&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;operations&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;reduce&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;p&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;f&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="nb"&gt;Promise&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;collection&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;.....&lt;/span&gt;  &lt;span class="c1"&gt;// array or object&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;finalResult&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sequence&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="nx"&gt;func1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;func2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nx"&gt;func3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;......&lt;/span&gt;
&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;BUT - this only gets us part of the way there.&lt;/p&gt;

&lt;h1&gt;
  
  
  Next (yes, running out of time again)
&lt;/h1&gt;

&lt;p&gt;The next article in this series will wrap it all up with a way in which we can use something inspired by MongoDB... more like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;collection&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="c1"&gt;// array of objects (or arrays for records)&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;transformed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;transformer&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;group&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;year&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;state&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]],&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;mutate&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;`${row.men + row.women}`&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}],&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;rename&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;total&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Total&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}]&lt;/span&gt;
&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;collection&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Stay tuned....&lt;/p&gt;

</description>
      <category>pipeline</category>
      <category>transformation</category>
      <category>javascript</category>
      <category>json</category>
    </item>
    <item>
      <title>Pluggable API and React (Series) - Tooling</title>
      <dc:creator>Gary Menzel</dc:creator>
      <pubDate>Mon, 28 Sep 2020 08:36:50 +0000</pubDate>
      <link>https://dev.to/garymenzel/pluggable-api-and-react-series-tooling-17n3</link>
      <guid>https://dev.to/garymenzel/pluggable-api-and-react-series-tooling-17n3</guid>
      <description>&lt;p&gt;Following on from the introduction, this post will talk about some of the tooling that I have recently been using and why it help support a pluggable API.&lt;/p&gt;

&lt;h1&gt;
  
  
  snowpack
&lt;/h1&gt;

&lt;p&gt;As many developers know, build (and dev) tools really help improve your productivity.  Also, like many React developers, I had been using Create React App (&lt;code&gt;cra&lt;/code&gt;) from the Facebook team.  It abstracts away the tedious setup of webpack for helping to give you a "live" development environment as well as being able to bundle up your code for deployment.&lt;/p&gt;

&lt;p&gt;However, I have recently cutover solely to Snowpack due to the speed in which it works and the non-lock-in to the supporting scripts which CRA requires you to "eject" from and then lose all the benefits.  Snowpack also is not as aggressive in the way it bundles your files during development and the Hot Module Reload also works very well.&lt;/p&gt;

&lt;p&gt;Unlike CRA, Snowpack has several templates to work with non-React frameworks.&lt;/p&gt;

&lt;p&gt;If you don't already know about Snowpack, take a look here:&lt;br&gt;
&lt;a href="https://www.snowpack.dev/"&gt;Snowpack&lt;/a&gt;.  It has a few small issues but all can be overcome easily.&lt;/p&gt;

&lt;h1&gt;
  
  
  yarn workspaces
&lt;/h1&gt;

&lt;p&gt;When developers are building modules for publication (on &lt;code&gt;npm&lt;/code&gt;) the common go-to tool is &lt;code&gt;lerna&lt;/code&gt;.  However, when you just want to have some separation of server and client (or clients) &lt;code&gt;yarn workspaces&lt;/code&gt; provides a nice way to have a mono-repo.  You can always upgrade to &lt;code&gt;lerna&lt;/code&gt; at a future point as they both can work together.  So, for this series, we will stay with &lt;code&gt;yarn workspaces&lt;/code&gt; and talk about some of the common usage commands with that.&lt;/p&gt;

&lt;h1&gt;
  
  
  react-hooks-global-state
&lt;/h1&gt;

&lt;p&gt;In the global state management space, many have heard of Redux and MobX.  These are very common but also have a fairly steep learning curve to master them.  They are also often overkill (and overhead) when you have a smaller development team with good communication lines.&lt;/p&gt;

&lt;p&gt;Fortunately, React Hooks have been around for a while now and there are some solid statement management solutions around.&lt;/p&gt;

&lt;p&gt;For this series I am going to stick with &lt;code&gt;react-hooks-global-state&lt;/code&gt; as the model is very simple to use and you CAN actually leverage your Redux knowledge of types, actions and reducers if you want.  I am also looking at a different version of the pluggable API that uses &lt;code&gt;zustand&lt;/code&gt;.  One of the benefits of &lt;code&gt;zustand&lt;/code&gt; over &lt;code&gt;react-hooks-global-state&lt;/code&gt; is that &lt;code&gt;zustand&lt;/code&gt; does not require an initial state to be created - allowing for more dynamic state at runtime.&lt;/p&gt;

&lt;p&gt;These tools come from the similar developers.  Both use React Hooks and both support the ability to interrogate and manipulate the state from outside of React.  This becomes important when you want to separate your backend API calls from your front-end components.&lt;/p&gt;

&lt;p&gt;Check out &lt;a href="https://www.npmjs.com/package/react-hooks-global-state"&gt;react-hooks-global-state&lt;/a&gt; and &lt;a href="https://www.npmjs.com/package/zustand"&gt;zustand&lt;/a&gt; just to become familiar with these packages.  We may end up referring to both.&lt;/p&gt;

&lt;h1&gt;
  
  
  Next...
&lt;/h1&gt;

&lt;p&gt;Next I will talk about the core parts of the pluggable API and we will start getting into some code.  I am planning have a git repo that will have a branch for each stage but will see how that pans out along the way.&lt;/p&gt;

</description>
      <category>snowpack</category>
      <category>api</category>
      <category>react</category>
      <category>hooks</category>
    </item>
    <item>
      <title>Pluggable API and React (Series) - Introduction</title>
      <dc:creator>Gary Menzel</dc:creator>
      <pubDate>Sat, 19 Sep 2020 12:05:00 +0000</pubDate>
      <link>https://dev.to/garymenzel/pluggable-api-and-react-series-introduction-2182</link>
      <guid>https://dev.to/garymenzel/pluggable-api-and-react-series-introduction-2182</guid>
      <description>&lt;h1&gt;
  
  
  What is this series about?
&lt;/h1&gt;

&lt;p&gt;In my development work over many years, I have built many APIs on both the front and backend of web-based systems.  Obviously, REST is a popular communications API and many server platforms provide libraries to organise and manage various features or "service" but what about the front end?&lt;/p&gt;

&lt;p&gt;This series is (probably) opinionated and is not specifically about &lt;code&gt;React&lt;/code&gt; (although the inspiration for this framework comes from &lt;code&gt;React&lt;/code&gt;). It is about building a framework that you can use to pass globalised and share all of your well-built functions for use within your React components.&lt;/p&gt;

&lt;p&gt;It does use various &lt;code&gt;React&lt;/code&gt; technologies (like hooks) where applicable but also adheres to the ideas of inversion of control and dependency injection - hence minimising imported modules and facilitating easier testing.&lt;/p&gt;

&lt;h1&gt;
  
  
  What will this series use?
&lt;/h1&gt;

&lt;p&gt;The focus is on front-end technology but will also demonstrate using HTTP calls for backend access.  It will also use &lt;code&gt;React&lt;/code&gt; for the front-end technology and &lt;code&gt;Snowpack&lt;/code&gt; as the development environment.  For global state management, the series will use &lt;code&gt;react-hooks-global-state&lt;/code&gt; rather than &lt;code&gt;Redux&lt;/code&gt; or &lt;code&gt;MobX&lt;/code&gt; - but you could probably apply similar ideas to those technologies or roll your own with &lt;code&gt;React Context&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Why would I want an API in my front-end app?
&lt;/h1&gt;

&lt;p&gt;If you are building a single-page-app (SPA) then it is likely that you have various components that share some type of global state.  I have found that applying separation to read/write of global state really helps organise an application and an API can help do that.  You can use React Hooks to read your data and an API to update your data (as well as provide side effects.&lt;/p&gt;

&lt;p&gt;Yes, &lt;code&gt;Redux&lt;/code&gt; and &lt;code&gt;MobX&lt;/code&gt; can provide that type of separation but, out-of-the-box, hook-based global state usually does not.  The reason for going with hook-based global state management is purely for consistency and minimal boilerplating.  This approach may not be suitable for larger developer organisations but works very well for smaller dev-ops style IT groups.&lt;/p&gt;

&lt;h1&gt;
  
  
  What next?
&lt;/h1&gt;

&lt;p&gt;This is just the introduction article.  In future articles I plan to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go into more detail about the tooling selection - such as Snowpack and react-hooks-global-state&lt;/li&gt;
&lt;li&gt;Work through the core of a pluggable API&lt;/li&gt;
&lt;li&gt;Demonstrate how to add variables and functions in a plugin and how to access the global API from those plugins&lt;/li&gt;
&lt;li&gt;Make suggestions about a component factory that allows each plugin to "extend" the API footprint &lt;/li&gt;
&lt;li&gt;And other relevant things as we flesh out the pluggable API and various plugins&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please join me on this journey and provide your feedback.&lt;/p&gt;

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