Adobe UXP: Things you need to know! #12 React JS

In this instalment Iā€™d like to tell you about ReactJS, and Iā€™ll take the chance to announce a brand new course of mine: Adobe UXP plugins development with ReactJS - Build products and Create a Business in the Creative Cloud Marketplace and Beyond.

So far in this series Iā€™ve only used Vanilla JavaScript to keep it simple, but in the real world a large part of plugin developers donā€™t like to reinvent the wheel themselves and end up using one of the available frameworks. And guess what, ReactJS is the most popular JavaScript library according to the StackOverflow 2021 survey. Even more than jQuery, check that out!

By the way, React JS is a Library and not a Framework (such Vue.js or Angular), do you know the difference? A Library is something that you ā€œplug in your codeā€, whereas a Framework is something ā€œyou plug your code intoā€ā€¦ subtle but meaningful difference! In other words, your code uses a Library, whereas your code is used by a Framework. This is what is generally referred to as ā€œInversion of Controlā€.

According to this definition, it turns out that React JS is in fact a library, i.e. some code that enhances ā€œregularā€ JavaScript adding useful features, but it doesnā€™t require you to buy into some opinionated way of structuring your source code, as Frameworks generally do.

React feats

So, what kind of feats made React JS so popular over the years? First of all, Components, a handy way to bundle into a custom element bits of user interface and logic.

<div>
  <Heading></Heading>
  <Slider></Slider>
  <Buttons></Buttons>
</div>

Creating a component is as easy as writing a function: that in React can return markup, i.e. HTML elements.

const Buttons = () => {
  return (
    <div className="buttons">
      <sp-button variant="secondary">Cancel</sp-button>
      <sp-button>Run</sp-button>
    </div>
  );
}

This is referred to as JSX: JavaScript Syntax Extension, or JavaScript XML. Those components can be passed Properties by the parent: they can make use of them, e.g. to display values via curly braces {} interpolation or to do whatever they have to do.

<!-- In the Parent -->
<ToggleButton message="Click me" bigger="true"/>

Here weā€™re passing a message and a bigger properties, that are then destructured and used in the component to set the Spectrum Button text and assign classes.

// In the Component
const ToggleButton = ({message, bigger}) => {
  return (
    <sp-button class={bigger === "true" ? "larger highlight" : "normal"}>
      {message}
    </sp-button>
  );
}

Thanks to Hooks, special React functions that give Components superpowers, you can e.g. create a State: a reactive property (alongside with its setter) that is able to trigger a component re-render when the property changes.

import { useState } from "react";

const ToggleButton = () => {
  const [ isOn, setIsOn ] = useState(false); // <- State
  return (
    <sp-action-button onClick={ () => setIsOn(!isOn) }>
      { isOn ? "Toggled ON" : "Toggled OFF" }
    </sp-action-button>
  );
}

In the example above, isOn is a boolean stored in the State; depending on its value, a different string is displayed in the Spectrum Action Button. The boolean is flipped in the buttonā€™s onClick handler via its setter setIsOn().

Reactivity is key here: youā€™re building declarative interfaces based on data, that are going to reflect changes in data as they happen. On the other side, with imperative code (e.g. jQuery) you have got to explicitly impart instructions to the UI on what to do, and when.

Obviously thereā€™s much more to React than Components and Hooks, but thanks to them and to JSX (the possibility to use JavaScript to compute HTML code) youā€™re able to build remarkably powerful User Interfaces.

For all your needs there is a large ecosystem of plugins: take State Management as an exampleā€”i.e. a unique place to store reactive data that is accessible to all components no matter their parent/child relation. React provides you with solid foundations only, but you can easily plug-in the library you like the most among the available ones: Redux, Recoil, MobX, Zustand, etc.

Why React

And not Vue, Angular, Svelteā€¦? Because: Adobe! You might not like this, but let me explain.

UXP, as weā€™ve seen over and over again throughout this series, is heavily inspired by standards, but it shouldnā€™t be considered a Browser environment. Hence, not everything that works in a Browser is to be expected to automatically work in a UXP plugin. As an example, until very (very!) recently, there wasnā€™t a document.createEvent() method, which is what Vue.js version 3 relies upon. Why was it missing? Because the UXP team has to willingly implement features, and that one didnā€™t happen to be high priority to them. As a result, for almost a year after the UXP announcement you couldnā€™t even load Vue.js v3.1

It also happens that React JS is exactly what Adobe uses for their own first-party features, like for instance the Welcome screen, the New File dialog, the Neural Filters interfaces: all UXP plugins. And you can bet that if React-next-version is going to need some Browser API that didnā€™t make into UXP yet, that very feature is going to be implemented at once. Because they wonā€™t risk Neural Filters to crash because of it, right? On the other hand, any other feature might take months to be implementedā€”as itā€™s happened with document.createEvent()

In other words, not only React is a solid choice thanks to the popularity of the library in the JavaScript ecosystem and the amount of available resources; given its adoption by Adobeā€™s engineering teams it has to be considered the safest choice, support-wise.

With any other framework, although they might work, youā€™reā€¦ more on your own. The [insert your framework of choice] might or might not work now, and might stop working when its newer version is released. ĀÆ\_(惄)_/ĀÆ

The UXP and React JS course

I was chatting with a developer friend once, and they said: ā€œIā€™ll start with Vanilla JS plugins, and when Iā€™m familiar with the environment Iā€™ll approach React JS. You know, I donā€™t want too much on my plateā€. Although it may sound considerate at first, I donā€™t buy it, IMHO thereā€™s a way better approach.

On the one side, learning a tool2 such as React for Reactā€™s sake, in some abstract/generic environment Ć  la ā€œletā€™s build a Todo app, or a Reddit cloneā€ is always going to be an inferior way, compared to learning it in the actual context in which youā€™re gonna use it: a UXP plugin. Not only youā€™re gonna save a huge lot of time, but it sucks way less.

Provided that somebody (i.e. yours truly) has figured out a learning path that combines UXP and React JS in such a way that youā€™re presented with a UXP problem, and given a gradually more complex React tool to solve it. So, hopefully, next time youā€™ll run into the same kind of problem in your own UXP plugins, itā€™ll come natural for you to reach out for that same React tool to hammer it. Much better than trying to fit some abstract example into the case at hand.

Moreover, thereā€™s a small(ish) subset of React features that allow you to accomplish a great deal of good in the UXP environment. Everybody love Venn Diagrams, isnā€™t that right?

The overlapping area is evident after youā€™ve drawn the two circles, i.e. after youā€™ve learned the two topics separately. But while youā€™re drawing (i.e. learning) them on your own? Youā€™ve no idea whether the React JS topic youā€™re approaching is going to be of fundamental importance, marginal, or just a waste of time. Wouldnā€™t it be better to start from this relatively approachable core of super-important topics instead, dealt with in the UXP plugins context to optimize your energies and time?

Thatā€™s precisely the Adobe UXP plugins development with React JS courseā€™s agenda.

Subtitled: ā€œBuild products and Create a Business in the Creative Cloud Marketplace and Beyondā€. Thereā€™s a fat section on the business of UXP plugins, from mundane but fundamental topics such as VAT, ecommerce providers etc. that I wish somebody told me when I started many years ago, up to a comparison of marketing strategies. With examples from a barely average marketeer and a very successful one (and by very successful I mean in the six-figures range) such as Micheal Bruny-Groth, the author of the Logo Package for Adobe Illustrator.

The course consists of a PDF ebook, ~290 pages lusciously typeset in LaTeX (a pain in the ass, but still luscious).

Then there are 16 demo plugins with fully commented code, from the ubiquitous ā€œAction buttonsā€ plugin, up more advanced topics such as React custom hooks, server-side communication, etc.

Iā€™ve also recorded 5 and a half hours of videotutorials, with theory, live coding, bug fixing and whatnot.

I definitely plan to add more content as UXP evolves. The course is offered in three different packages:

  • Basic: Book + Code samples
  • Complete: Book + Code samples + Videos (streaming only)
  • Enterprise: Book + Code samples + Videos (downloadable, licensed for teams up to 10 seats strong)

For more info and FAQ check out the course home at PS-Scripting.com.


Thanks for following along! If you find this content useful, please consider supporting me: you can either purchase my latest UXP Course with ReactJS, or donate what you can like the following fine people didā€”itā€™ll be much appreciated! šŸ™šŸ»

Thanks to: John Stevenson ā­ļø, Adam Plouff, Dana Frenklach, Dmitry Egorov, Roberto Sabatini, Carlo Diamanti, Wending Dai, Pedro Marques, Anthony Kuyper, Gabriel Correia, Ben Wright, CtrlSoftware, Maiane Araujo, MihĆ”ly DĆ”vid Paseczki, Caspar Shelley.

Stay safe, get the Nth vaccine shot if/when you can ā€“ bye!

The whole series so far


  1. Vue.js version 2 worked fine out of the box, instead.Ā 

  2. To me, React is just a tool to get the job done: Iā€™m not a zealot, Iā€™m not interested in JavaScript frameworks religion wars.Ā