<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>frontend on Ole Gensch</title>
    <link>/tags/frontend/</link>
    <description>Recent content in frontend on Ole Gensch</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Thu, 20 May 2021 08:54:39 +0200</lastBuildDate><atom:link href="/tags/frontend/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>React and Konva 01: Getting Started</title>
      <link>/posts/react-and-konva-getting-started/</link>
      <pubDate>Thu, 20 May 2021 08:54:39 +0200</pubDate>
      
      <guid>/posts/react-and-konva-getting-started/</guid>
      <description>Let&amp;rsquo;s take a look at how to get started with drawing shapes in a React app using the Konva.js canvas library/framework.
This is a short step-by-step guide to set up a React app and draw a simple shape in it. But first, let&amp;rsquo;s take a quick look at what we are gonna be working with:
React: React is a front-end framework developed and maintained by Facebook. It is highly popular in the frontend community (take a look at the statistics) and boosts with an enormous eco-systems consisting of thousands of packages.</description>
      <content>&lt;p&gt;Let&amp;rsquo;s take a look at how to get started with drawing shapes in a &lt;a href=&#34;https://reactjs.org/&#34;&gt;React&lt;/a&gt; app using the &lt;a href=&#34;https://konvajs.org/&#34;&gt;Konva.js&lt;/a&gt; canvas library/framework.&lt;/p&gt;
&lt;p&gt;This is a short step-by-step guide to set up a React app and draw a simple shape in it. But first, let&amp;rsquo;s take a quick look at what we are gonna be working with:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;React:&lt;/strong&gt; React is a front-end framework developed and maintained by Facebook. It is highly popular in the frontend community (take a look at the &lt;a href=&#34;https://hotframeworks.com/&#34;&gt;statistics&lt;/a&gt;) and boosts with an enormous eco-systems consisting of thousands of packages.&lt;br&gt;
The bare React-Framework is mostly being used to develop Single Page Applications, but there are other frameworks build on top of the React-Framework for developing other types of applications. An example of that would be the &lt;a href=&#34;https://nextjs.org/&#34;&gt;Next.js&lt;/a&gt; framework which is used to develop highly SEO-friendly Server-side rendered websites.
In this short guide, we are gonna be using the bare React-Framework, but the steps should also be possible in most React deviations (like Next.js).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Konva:&lt;/strong&gt; Konva.js is an object-oriented framework for drawing 2D shapes in the browser. It is built on top of the HTML5 canvas functionality and includes features like scaling, rotation, event handling, and animation.&lt;br&gt;
In this guide, we will be using the &lt;a href=&#34;https://github.com/konvajs/react-konva&#34;&gt;react-konva&lt;/a&gt; package. This package ports most of the Konva objects to React components that we can simply include in our code.&lt;/p&gt;
&lt;p&gt;Now that we have a rough understanding of what we will be using, we can finally start.&lt;/p&gt;
&lt;h1 id=&#34;setting-up-the-project&#34;&gt;Setting Up the Project&lt;/h1&gt;
&lt;p&gt;To get started with this guide we need to create a new React app. For this, we will be npx and the handy &lt;em&gt;create-react-app&lt;/em&gt; scaffolding.&lt;br&gt;
This command set&amp;rsquo;s up most of what we need to start.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;npx create-react-app react-konva-tutorial &lt;span style=&#34;color:#f92672&#34;&gt;&amp;amp;&amp;amp;&lt;/span&gt; cd react-konva-tutorial
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;After executing the command your folder should look somewhat like this:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;/img/react-konva-folder-structure.png&#34; alt=&#34;create-react-app-folder-structure&#34;&gt;&lt;/p&gt;
&lt;p&gt;Now we can proceed with installing Konva in our react app. Thanks to the previously mentioned react-konva this is actually quite easy:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;npm install react-konva konva
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;With our dependencies installed we can start up the development server and write some code to display beautiful 2D shapes.&lt;/p&gt;
&lt;p&gt;Starting the development server on Port 3000:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;yarn start
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h1 id=&#34;writing-some-code&#34;&gt;Writing some Code&lt;/h1&gt;
&lt;p&gt;After executing &lt;em&gt;create-react-app&lt;/em&gt; we are presented with a default App component, which looks something like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;src&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;App&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;js&lt;/span&gt;

&lt;span style=&#34;color:#66d9ef&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;logo&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;from&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;./logo.svg&amp;#39;&lt;/span&gt;;
&lt;span style=&#34;color:#66d9ef&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;./App.css&amp;#39;&lt;/span&gt;;

&lt;span style=&#34;color:#66d9ef&#34;&gt;function&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;App&lt;/span&gt;() {
  &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; (
    &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;div&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;className&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;App&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&lt;/span&gt;
      &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;header&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;className&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;App-header&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&lt;/span&gt;
        &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;img&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;src&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;{&lt;span style=&#34;color:#a6e22e&#34;&gt;logo&lt;/span&gt;} &lt;span style=&#34;color:#a6e22e&#34;&gt;className&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;App-logo&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;alt&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;logo&amp;#34;&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;p&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&lt;/span&gt;
          &lt;span style=&#34;color:#a6e22e&#34;&gt;Edit&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;code&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;src&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;App&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;js&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#960050;background-color:#1e0010&#34;&gt;/code&amp;gt; and save to reload.&lt;/span&gt;
        &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#960050;background-color:#1e0010&#34;&gt;/p&amp;gt;&lt;/span&gt;
        &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;a&lt;/span&gt;
          &lt;span style=&#34;color:#a6e22e&#34;&gt;className&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;App-link&amp;#34;&lt;/span&gt;
          &lt;span style=&#34;color:#a6e22e&#34;&gt;href&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;https://reactjs.org&amp;#34;&lt;/span&gt;
          &lt;span style=&#34;color:#a6e22e&#34;&gt;target&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;_blank&amp;#34;&lt;/span&gt;
          &lt;span style=&#34;color:#a6e22e&#34;&gt;rel&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;noopener noreferrer&amp;#34;&lt;/span&gt;
        &lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&lt;/span&gt;
          &lt;span style=&#34;color:#a6e22e&#34;&gt;Learn&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;React&lt;/span&gt;
        &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#960050;background-color:#1e0010&#34;&gt;/a&amp;gt;&lt;/span&gt;
      &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#960050;background-color:#1e0010&#34;&gt;/header&amp;gt;&lt;/span&gt;
    &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#960050;background-color:#1e0010&#34;&gt;/div&amp;gt;&lt;/span&gt;
  );
}

&lt;span style=&#34;color:#66d9ef&#34;&gt;export&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;default&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;App&lt;/span&gt;;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We should clean it up a bit before proceeding. We are removing basically everything currently display and replace it with a simple text display.&lt;br&gt;
So let&amp;rsquo;s just throw out the entire &lt;code&gt;&amp;lt;header&amp;gt;&lt;/code&gt;-component and every &lt;code&gt;import&lt;/code&gt;-statement that is now unused, and then add a &lt;code&gt;&amp;lt;p&amp;gt;&lt;/code&gt;-tag. &lt;br&gt;
This leaves us with this setup:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;src&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;App&lt;/span&gt;.&lt;span style=&#34;color:#a6e22e&#34;&gt;js&lt;/span&gt;

&lt;span style=&#34;color:#66d9ef&#34;&gt;import&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;./App.css&amp;#39;&lt;/span&gt;;

&lt;span style=&#34;color:#66d9ef&#34;&gt;function&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;App&lt;/span&gt;() {
  &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; (
    &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;div&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;className&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;App&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&lt;/span&gt;
      &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;p&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;Hello&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;There&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#960050;background-color:#1e0010&#34;&gt;/p&amp;gt;&lt;/span&gt;
    &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#960050;background-color:#1e0010&#34;&gt;/div&amp;gt;&lt;/span&gt;
  );
}

&lt;span style=&#34;color:#66d9ef&#34;&gt;export&lt;/span&gt; &lt;span style=&#34;color:#66d9ef&#34;&gt;default&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;App&lt;/span&gt;;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Now we add our previously installed konva objects. At the top of the file we add a new &lt;code&gt;import&lt;/code&gt;-statement.&lt;br&gt;
This imports the 3 components: &lt;strong&gt;Stage&lt;/strong&gt;, &lt;strong&gt;Layer&lt;/strong&gt;, and &lt;strong&gt;Star&lt;/strong&gt; into the current app component.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;...
&lt;span style=&#34;color:#66d9ef&#34;&gt;import&lt;/span&gt; { &lt;span style=&#34;color:#a6e22e&#34;&gt;Stage&lt;/span&gt;, &lt;span style=&#34;color:#a6e22e&#34;&gt;Layer&lt;/span&gt;, &lt;span style=&#34;color:#a6e22e&#34;&gt;Star&lt;/span&gt; } &lt;span style=&#34;color:#a6e22e&#34;&gt;from&lt;/span&gt; &lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#39;react-konva&amp;#39;&lt;/span&gt;
...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;&lt;strong&gt;Stage:&lt;/strong&gt; The Stage is the start of the entire Konva architecture. It is the container for one or multiple layers and needs to be present whenever we want to draw something.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Layer:&lt;/strong&gt; The layer is the first component beneath the Stage. A layer has two renderers for the canvas: one for rendering the scene and another for detecting events.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Star:&lt;/strong&gt;  This is the shape we will be drawing in our application. This react component has properties we can later set to determine how the shape will be drawn. Some examples we will be using are number of points, radius (inner and outer), and color.&lt;/p&gt;
&lt;p&gt;Konva.js supports much more than the simple structure we are aiming for. It is easily possible to draw complex shapes, draw over multiple layers, or group objects.&lt;/p&gt;
&lt;p&gt;Check out the &lt;a href=&#34;https://konvajs.org/docs/how_it_works.html&#34;&gt;official Konva.js documentation&lt;/a&gt; for more information on this.&lt;/p&gt;
&lt;p&gt;We can now proceed with displaying a simple shape in our application.
For this we will be adding the previously imported components in the following order:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;Stage ---&amp;gt; Layer ----&amp;gt; Star
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Before we can see our shape, we need to configure the Stage and Star components.&lt;br&gt;
The stage needs to be initialized with a width and height, as everything below it is rendered dynamically and can&amp;rsquo;t be used to compute the needed height and width of its parent.&lt;br&gt;
In this example, we are setting the dimensions to the ones of our window.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;...
&lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;Stage&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;width&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;{window.&lt;span style=&#34;color:#a6e22e&#34;&gt;innerWidth&lt;/span&gt;} &lt;span style=&#34;color:#a6e22e&#34;&gt;height&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;{window.&lt;span style=&#34;color:#a6e22e&#34;&gt;innerHeight&lt;/span&gt;}&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&lt;/span&gt;
...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The star component needs a few more properties to be visible. The first needed property is the position of the star component.&lt;br&gt;
This is expressed as x and y coordinates and we will be setting them to half of our width and height so that the star is displayed right in the center.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;x&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;{window.&lt;span style=&#34;color:#a6e22e&#34;&gt;innerWidth&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;}
&lt;span style=&#34;color:#a6e22e&#34;&gt;y&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;{window.&lt;span style=&#34;color:#a6e22e&#34;&gt;innerHeight&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Next up we need to configure the actual shape of the star. Therefore we set the number of points (or jags), as well as the inner and outer radius.&lt;br&gt;
The radiuses determine where the jags of the star start and end.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;numPoints&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;{&lt;span style=&#34;color:#ae81ff&#34;&gt;5&lt;/span&gt;}
&lt;span style=&#34;color:#a6e22e&#34;&gt;innerRadius&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;{&lt;span style=&#34;color:#ae81ff&#34;&gt;20&lt;/span&gt;}
&lt;span style=&#34;color:#a6e22e&#34;&gt;outerRadius&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;{&lt;span style=&#34;color:#ae81ff&#34;&gt;40&lt;/span&gt;}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;We now have a star, but we can&amp;rsquo;t see it yet. To be able to see it, we need to give it a color different from the default white of the background.&lt;br&gt;
I chose green as a color, but feel free to choose whatever you like.&lt;/p&gt;
&lt;p&gt;To sum it all up, this leaves us with the following snippet of code within our App component:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-js&#34; data-lang=&#34;js&#34;&gt;  ...
  &lt;span style=&#34;color:#66d9ef&#34;&gt;return&lt;/span&gt; (
    &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;div&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;className&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;App&amp;#34;&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&lt;/span&gt;
      &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;Stage&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;width&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;{window.&lt;span style=&#34;color:#a6e22e&#34;&gt;innerWidth&lt;/span&gt;} &lt;span style=&#34;color:#a6e22e&#34;&gt;height&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;{window.&lt;span style=&#34;color:#a6e22e&#34;&gt;innerHeight&lt;/span&gt;}&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&lt;/span&gt;
        &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;Layer&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;&amp;gt;&lt;/span&gt;
          &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#a6e22e&#34;&gt;Star&lt;/span&gt; 
            &lt;span style=&#34;color:#a6e22e&#34;&gt;x&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;{window.&lt;span style=&#34;color:#a6e22e&#34;&gt;innerWidth&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;}
            &lt;span style=&#34;color:#a6e22e&#34;&gt;y&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;{window.&lt;span style=&#34;color:#a6e22e&#34;&gt;innerHeight&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;/&lt;/span&gt; &lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;}
            &lt;span style=&#34;color:#a6e22e&#34;&gt;numPoints&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;{&lt;span style=&#34;color:#ae81ff&#34;&gt;5&lt;/span&gt;}
            &lt;span style=&#34;color:#a6e22e&#34;&gt;innerRadius&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;{&lt;span style=&#34;color:#ae81ff&#34;&gt;20&lt;/span&gt;}
            &lt;span style=&#34;color:#a6e22e&#34;&gt;outerRadius&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;{&lt;span style=&#34;color:#ae81ff&#34;&gt;40&lt;/span&gt;}
            &lt;span style=&#34;color:#a6e22e&#34;&gt;fill&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;&lt;span style=&#34;color:#e6db74&#34;&gt;&amp;#34;#0f0&amp;#34;&lt;/span&gt;
            &lt;span style=&#34;color:#a6e22e&#34;&gt;opacity&lt;/span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt;{&lt;span style=&#34;color:#ae81ff&#34;&gt;0.8&lt;/span&gt;}
          &lt;span style=&#34;color:#f92672&#34;&gt;/&amp;gt;&lt;/span&gt;
        &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#960050;background-color:#1e0010&#34;&gt;/Layer&amp;gt;&lt;/span&gt;
      &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#960050;background-color:#1e0010&#34;&gt;/Stage&amp;gt;&lt;/span&gt;
    &lt;span style=&#34;color:#f92672&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&#34;color:#960050;background-color:#1e0010&#34;&gt;/div&amp;gt;&lt;/span&gt;
  );
  ...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;And if we now switch over to our browser and go to http://localhost:3000 we can see our star.&lt;/p&gt;
&lt;p&gt;I hope you enjoyed this quick read and that it helped you to get started with Konva and React.&lt;br&gt;
I am thinking about extending this guide to include topics like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Transformation (Dragging, Rotating and Scaling Shapes)&lt;/li&gt;
&lt;li&gt;Implementing a selection box&lt;/li&gt;
&lt;li&gt;Group Transformations&lt;/li&gt;
&lt;li&gt;Implementing a menu to dynamically add and remove shapes&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So leave me a comment if you are interested in of those topics and see you next time!&lt;/p&gt;
</content>
    </item>
    
  </channel>
</rss>
