Skip to content

Commit

Permalink
chore: add a link to online code
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-elkin committed Dec 6, 2024
1 parent b3d20fa commit 890ca3a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/content/posts/2024-12-06-React-19.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,26 @@ It's understandable why library authors chose to encapsulate all this complexity

## Code examples

> 💻
> You can try all the code here: https://stackblitz.com/~/github.com/aleks-elkin/react-web-components
Fortunately, React 19 resolves all these issues. Let's create a two React apps with React 18 and React 19 that uses the same web component, `web-counter`, and compare.

`web-counter` is a simple component, that has an increment button and displays a current value. It has:

- One boolean attribute, `isdark` that changes the color of the text depending on the current color scheme.
- One property `increment` with type `{ value : number }`, that allows to set up the increment value.
- It emits a `CustomEven` “IncrementedEvent” with the current value as a payload.


You can view the complete code here: [web-counter](https://github.com/aleks-elkin/react-web-components/blob/main/packages/web-components/web-counter.js)

I chose vanilla JS for implementation - while this makes the code longer, it ensures pure compatibility with Web Standards.

In the React app, we want to:
- change the color scheme between light and dark
- switch the increment value between 1 and 2
- track the total number of button clicks by subscribing to the "IncrementedEvent" `CustomEvent`

- change the color scheme between light and dark
- switch the increment value between 1 and 2
- track the total number of button clicks by subscribing to the "IncrementedEvent" `CustomEvent`

This is how it will look in the browser:

Expand Down Expand Up @@ -134,6 +138,7 @@ So, let’s compare, how our code changed thanks to improvements introduced in R
- No need for artificial properties object to work with boolean attributes.

### All transformations are summarized on this picture:

![image info](/static/comparison.png)
[link to a bigger image](/static/comparison.png)

Expand Down

0 comments on commit 890ca3a

Please sign in to comment.