<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kurniawan Cristianto on Medium]]></title>
        <description><![CDATA[Stories by Kurniawan Cristianto on Medium]]></description>
        <link>https://medium.com/@kurniawanc?source=rss-3ce190be97c4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1XTCtSHOmjMHPtgFi_n6pQ.png</url>
            <title>Stories by Kurniawan Cristianto on Medium</title>
            <link>https://medium.com/@kurniawanc?source=rss-3ce190be97c4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 09:52:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kurniawanc/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Introduction to NestJS]]></title>
            <link>https://medium.com/@kurniawanc/introduction-to-nestjs-addb9a928745?source=rss-3ce190be97c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/addb9a928745</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nestjs]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Kurniawan Cristianto]]></dc:creator>
            <pubDate>Wed, 27 Sep 2023 15:33:20 GMT</pubDate>
            <atom:updated>2023-09-27T15:33:20.110Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/820/0*6egbHmflMYt97P9_.png" /><figcaption>NestJS</figcaption></figure><p>Hi everyone, today i will be writing about introduction to NestJS and how you can create a new NestJS project using Nest CLI.</p><h3>About NestJS</h3><p>NestJS is a backend NodeJS framework for building server-side applications. It fully supports Typescript and the architecture is heavily inspired by Spring Boot (Java). Under the hood, it wraps around ExpressJS or Fastify to create the server. You can create many useful applications like REST API, Websocket, Microservices server and many more using it. NestJS also have a pretty good documentation which you can see <a href="https://docs.nestjs.com/">here</a>.</p><h3>Nest CLI</h3><p>NestJS provides a CLI tool called Nest CLI and it’s pretty powerful and helpful to used when working with NestJS projects. In this guide, we will use Nest CLI to help us for building our app.</p><p>To install Nest CLI, you can use command below :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ng0QMg7EXv508UiXzjPSpA.png" /><figcaption>Install Nest CLI using NPM</figcaption></figure><p>With command above, we will use our package manager (npm) to install Nest CLI globally in our computer so we can use it whenever we want with <strong><em>nest</em></strong> command.</p><h3>Create New NestJS Project</h3><p>We can easily create new NestJS project by using this Nest CLI command :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KZaNsaElFatTT7lnIteBGA.png" /><figcaption>Create New NestJS Project</figcaption></figure><p>This command will create and scaffold new NestJS project with project name you specified. The project name (<em>nest-rest-api</em>) is flexible and you can change it homever you want. The project name will also become your project folder name. I added <strong>— strict</strong> flag to defaultly enable strict feature in Typescript so our code will become more safe and reliable.</p><h3>Project Structure</h3><p>After creating NestJS project, we can open it in our favorite code editor (i’m using <a href="https://www.jetbrains.com/webstorm/">Webstorm</a>). We can see the project files structure below :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*TMVQz1eMv-txbq4I3bWhtg.png" /><figcaption>NestJS Files Project Structure</figcaption></figure><p>I will try to explain about the files project structure as simple as i can :</p><ul><li>node_modules =&gt; folder containing all of the npm libraries that we need</li><li>src =&gt; folder containing your app main source code</li><li>test =&gt; folder containing tests file for E2E app testing</li><li>.eslintrc.js =&gt; file containing ESLint configuration for code linting</li><li>.gitignore =&gt; file containing selected file to exclude from Git repository</li><li>.prettierrc =&gt; file containing Prettier configuration for code formatting</li><li>nest-cli.json =&gt; file containing Nest CLI configuration</li><li>package.json =&gt; file containing npm project configuration and npm dependencies</li><li>package-lock.json =&gt; file generated by npm automatically to record exact package dependency version</li><li>README.md =&gt; file containing markup to display and explain about project</li><li>tsconfig.build.json =&gt; file containing Typescript configuration for production build</li><li>tsconfig.json =&gt; file containing Typescript configuration for development</li></ul><p>When building your app, you will usually works with <strong>src</strong> folder because it mainly store all of your app code. Next, i will be explaining about <strong>src</strong> folder and NestJS primary building blocks.</p><h3>Src Folder &amp; NestJS Main Concepts</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*pflGSRUMX22SfmU0hzaydg.png" /><figcaption>Src Folder Structure</figcaption></figure><p>From the src folder, we can see that NestJS App mainly consists of several components :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4UQUfwxz5Hm2Z7KmHeDHyA.png" /><figcaption>app.service.ts</figcaption></figure><ul><li>app.service.ts =&gt; This is the <strong>service</strong> component. <strong>Service</strong> is a class that contains several functions (like to manage data) according to the service name. Usually, service will be connecting the app with database repository to manage data. One of the service unique traits is <strong>injectable</strong>. That means the service can be injected and used from other component if we need it. The <strong>Injectable()</strong> decorator is used to mark a class as Service component.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*16QFOAUEukDh1o5aBdHPfw.png" /><figcaption>app.controller.ts</figcaption></figure><ul><li>app.controller.ts =&gt; This is the <strong>controller</strong> component. <strong>Controller</strong> is a class that contains several method to manage app routing and incoming request. Usually, controller will manage the request and response of the app with the help of service that injected into it. The <strong>Controller() </strong>decorator is used to mark a class as Controller component.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bx-q_fOJznwHx9Ra_FbAYQ.png" /><figcaption>app.module.ts</figcaption></figure><ul><li>app.module.ts =&gt; This is the <strong>module</strong> component. <strong>Module</strong> is a class that contains application structure configuration. Module will be used to combine and connecting all of service and controller used by the component according to module name. NestJS app usually consists of many modules with each modules have their own responsibilities like Data and Auth module. The <strong>Module()</strong> decorator is used to mark a class as Module component.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OuoAZ_uZqz1K_Gxzh4R0Hg.png" /><figcaption>main.ts</figcaption></figure><ul><li>main.ts =&gt; This is the <strong>main</strong> root file to run the app. It consist of a single function to bootstrap and run the app. We can also configure the app in bootstrap function before being run. Usually we will be injecting global service to use in our app globally.</li></ul><p>Those essential four components mainly forms a NestJS App. In bigger project, we can divide components into several folder as needed like Auth and Products folder with each within their own controller, service, and module.</p><p>That’s it for the introduction, you can view more information at NestJS official docs (<a href="https://docs.nestjs.com/">https://docs.nestjs.com</a>). I was planning to post REST API guide using NestJS soon.</p><p>Thank you for reading this post, I’m sorry if there is any wrong information and you can correct / ask me in comments section.</p><p>If you like and want more of these contents you can follow me on <a href="https://medium.com/@kurniawanc">Medium</a> and <a href="https://github.com/WawanC">Github</a>. You can also contact me for work related stuff on my <a href="https://www.linkedin.com/in/kurniawanc/">Linkedin</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=addb9a928745" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learn Supabase JS #1 : Database]]></title>
            <link>https://medium.com/@kurniawanc/learn-supabase-js-1-database-f074fe7a8512?source=rss-3ce190be97c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/f074fe7a8512</guid>
            <category><![CDATA[supabase]]></category>
            <category><![CDATA[javascript-library]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Kurniawan Cristianto]]></dc:creator>
            <pubDate>Wed, 22 Feb 2023 06:59:04 GMT</pubDate>
            <atom:updated>2023-02-22T06:59:04.116Z</atom:updated>
            <content:encoded><![CDATA[<h3>Learn Supabase JS #1 : Database</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gk0riWsLxMsyTOh3.jpg" /><figcaption>Supabase</figcaption></figure><p>Hi everyone, today i will be continuing my guide about SupabaseJS. In this guide, we will be learning about how to interact with Supabase BaaS database and using it through the help of SupabaseJS library.</p><p>Before we begin, make sure you’ve already created or have a Supabase project and a React project with SupabaseJS installed and initialized in it. If you don’t know how to do either both of it, you can view my guide before <a href="https://medium.com/@kurniawancristianto/learn-supabase-js-0-introduction-41f582918136">here</a>.</p><p>There are four main things to do when interacting with database. Those are Create, Read, Update and Delete data (CRUD). Using SupabaseJS, we can perform those actions on Supabase database using method provided by the library.</p><p>In this guide, i will make a simple book app with CRUD ability for user.</p><p>Supabase uses SQL database for the database by default (PostgreSQL) which means inside database contains many tables to store data. You can read and learn about the SQL database on the internet.</p><p>We must create a table to store data. You can create a new table in your database by going to the project dashboard and click on the Table Editor menu in the sidebar. Then you can click on New Table button to create a new table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*_eq8XdPUI5p-Wwffkf9JEQ.png" /><figcaption>New Table button</figcaption></figure><p>After that you can fill the required table information like table name, column and constraint, etc. You need to have an understanding of SQL database to create it. In this case, i will create a simple books table with basic book information like id, title, author, and year. You can disable the Row Level Security (RLS) option to disable the restricted access and we can easily insert data into it later without authorization. In real-life scenarios, you need this option to ensure security across your tables. Finally, you can click Save button to create the table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2aUsNDF2Wm0MjD8SitSHmg.png" /><figcaption>New Table Form</figcaption></figure><p>After creating the table, we can start implement CRUD feature in our React app.</p><p>First and foremost, i will do the coding in Typescript, which means i need to make some preparations to improve the type-safety. Usually i create a models folder to holds all the interfaces and functions about used entities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KgTG5i4h0zF9C_N5y-xejw.png" /><figcaption>models/book.tsx</figcaption></figure><h3>Create Data</h3><p>To create a new data, we can use insert() method with entity data passed to the arguments. Before doing all operations in a table, we must specify the table name first using from() method. In this case, id is not passed because it is auto-generated using uuid. We can error data from this method to handle error case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7qcyayVoDa6s7d_8GN3ALQ.png" /><figcaption>Create Book Method</figcaption></figure><h3>Read Data</h3><p>To read or get data from table, we can use select() method. Before doing all operations in a table, we must specify the table name first using from() method. We can get data and error from this method to return it or handle error case. To get the type of the entity, we can cast the returned data to array of entity type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lG0BJ_-CWQ1Z_zsLyNwXHQ.png" /><figcaption>Get Books Method</figcaption></figure><h3>Update Data</h3><p>To update data, we can use update() method with selected data id and updated entity data passed to the arguments. Before doing all operations in a table, we must specify the table name first using from() method. We must specify the selected data to be updated using eq() with data id passed to it .We can get error data from this method to handle error case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uDQrxq6K_ioKMzJ_wsQ6fw.png" /><figcaption>Update Book Method</figcaption></figure><h3>Delete Data</h3><p>To update data, we can use delete() method with selected data id passed to the arguments. Before doing all operations in a table, we must specify the table name first using from() method. We must specify the selected data to be deleted using eq() with data id passed to it .We can get error data from this method to handle error case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RHjzFgBukDF4ZgLCzFdygg.png" /><figcaption>Delete Book Method</figcaption></figure><p>Finally, after you create all of that method you can start implement that in your component. In this case, i used it in my App component to display a table list of books.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U2aSAG7tEDbwem57M39whQ.png" /><figcaption>App.tsx</figcaption></figure><p>That’s it for the basic database operational with SupabaseJS client library, you can view more information at SupabaseJS official docs (<a href="https://supabase.com/docs">https://supabase.com/docs</a>).</p><p>Thank you for reading this guide, if you like and want more of these contents you can follow me on Medium.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f074fe7a8512" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learn Supabase JS #0 : Introduction]]></title>
            <link>https://medium.com/@kurniawanc/learn-supabase-js-0-introduction-41f582918136?source=rss-3ce190be97c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/41f582918136</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[supabase]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Kurniawan Cristianto]]></dc:creator>
            <pubDate>Mon, 20 Feb 2023 07:58:32 GMT</pubDate>
            <atom:updated>2023-02-20T07:58:32.904Z</atom:updated>
            <content:encoded><![CDATA[<h3>Learn Supabase JS #0 : Introduction</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QJENKLGjIFRjIruy.jpg" /><figcaption>Supabase</figcaption></figure><p>Supabase is an open source backend-as-a-service (BaaS) with many features such as database, authentication, edge functions, etc. Supabase is built with purpose to be the alternative of another popular backend-as-a-service, Firebase which is created by Google. Supabase provides free plan for their service which is more than enough for small and hobby projects.</p><h3>What is backend-as-a-service (BaaS) ?</h3><p>Backend-as-a-service is a web service created by some company to provides user (which usually a developer) a backend service to used. Usually, Baas contains many backend core features such as database dan authentication. User (developer) can access it through REST API created automatically by it or through language-specific library provided by the company. This service makes it really easy for developer to make a backend server without actual knowledge of backend coding. The setup is also pretty fast so it compatible for prototyping a test project server. For React JS developer, BaaS is very useful because you can have a backend server to save and modify data without actually make it.</p><h3>Supabase JS</h3><p>Supabase also provides a library for Javascript developer called Supabase JS. This library consists of many function for Supabase feature such as Database, Authentication, Storage and etc. We can use SupabaseJS client library to access those feature. This library can be installed through package manager (such as npm or yarn) or through CDN. In this guide series, i will be use SupabaseJS alongside with React JS.</p><p>With React JS, we can install SupabaseJS through package manager and make our app access the backend server and it’s feature through it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZswI92-oDBj-xehU-OhhnQ.png" /><figcaption>SupabaseJS Project Architecture</figcaption></figure><h3>Project Setup</h3><p>To create a Supabase backend server, you need to go to it’s official website and create an account there (<a href="https://supabase.com/">https://supabase.com</a>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sPZ0grgee_AxMKVyYIE7Rw.png" /><figcaption>Supabase Official Website</figcaption></figure><p>Then in your dashboard page, you can create a new project by clicking at New Project button and choose your organization (in this case, personal)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rIw0R0cqsLXovei_idc2vA.png" /><figcaption>Dashboard Page</figcaption></figure><p>After that, you must fill a form with a project information such as project name, database password, region, etc. When you done filling that, you can click the Create new project button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y0GZJav5RmcP1_6ZU_-OVA.png" /><figcaption>New Project Form</figcaption></figure><p>Finally, your project server will be created and it will show you the project API keys and project URL. You need this information to use it later with SupabaseJS client library. Don’t worry, you can view this information again at your project setting later.</p><h3>Installation</h3><p>In this guide, we will install SupabaseJS in React JS app through package manager with this command :</p><p><em>npm install @supabase/supabase-js</em></p><p>After that, we can start using SupabaseJS client library in our project. But before that, we need to initialize it first using createClient() method provided by SupabaseJS. We must pass our supabase project URL and supabase project API key to that method.</p><p>For best practice, we can create a new javascript file to initialize the SupabaseJS client into a variable for easier use later. This also make the code more cleaner and reusable. Project URL and API key is confidential so it need to be a secret. We can use environment variable to hide it from public.</p><p>Lastly, we can export the supabase variable to use it in another components later.</p><p>In this case, i will be use Typescript for these example but you can still use Javascript :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GieJw2zMZrt4awLC5tc6Vw.png" /><figcaption>supabase.tsx</figcaption></figure><p>That’s it for the introduction, you can view more information at SupabaseJS official docs (<a href="https://supabase.com/docs">https://supabase.com/docs</a>). I will be posted another SupabaseJS guide soon.</p><p>Thank you for reading this guide, if you like and want more of these contents you can follow me on Medium.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41f582918136" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create multiple drag and drop list like Trello in React JS using dnd-kit library]]></title>
            <link>https://medium.com/@kurniawanc/create-multiple-drag-and-drop-list-like-trello-in-react-js-using-dnd-kit-library-b2acd9a65fab?source=rss-3ce190be97c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2acd9a65fab</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[javascript-library]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Kurniawan Cristianto]]></dc:creator>
            <pubDate>Sun, 19 Feb 2023 10:05:57 GMT</pubDate>
            <atom:updated>2023-02-19T10:05:57.140Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lJqh1Akk97NTISQN.png" /><figcaption>dnd-kit</figcaption></figure><p>Hi everyone, today i will show you how to create and implement multiple drag and drop list feature like in Trello for your React JS project by using <em>dnd-kit </em>library. I already create two guide about <em>dnd-kit</em> library, you can view it in my <em>dnd-kit</em> stories list <a href="https://medium.com/@kurniawancristianto/list/dndkit-14662f1d9770">here</a>.</p><p>FYI, dnd-kit is a library used to help make and implement drag and drop interfaces in your React JS app (<a href="https://dndkit.com/">https://dndkit.com</a>). The dnd-kit library provides many built-in component to help you implement drag and drop interfaces like Droppable, Draggable and Sortable component. If you haven’t familiar with it, you must check my other stories about <em>dnd-kit</em>.</p><p>For this guide, i will create a task board app where it consists of multiple column list and each task can be drag around to another column (like in Trello).</p><p>In this project, i will use following technologies :</p><ul><li>React JS for UI library</li><li>Typescript for language</li><li>CSS Modules for styling</li><li><em>dnd-kit </em>to implement drag and drop feature</li></ul><p>First, i will create and empty React JS project (you can also use it on existing project). Then, i will install the <em>dnd-kit </em>library package required to implement the features using these command :</p><p><em>npm install @dnd-kit/core @dnd-kit/sortable</em></p><p>Next, i will create just a basic view for the app in App component without the drag and drop functionality. I will store the tasks data using object inside a state for reactivity later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/488/1*6VDkX3OJTxDs8p-udxbtxg.png" /><figcaption>Initial Files Structure</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B7JGuy6WqypLk0UFMnH_EA.png" /><figcaption>App.tsx</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iSkWEQdKElrCQrtc3a7new.png" /><figcaption>Initial App Preview</figcaption></figure><p>Then, i will start by wrap the app with DndContext component to provides the drag and drop feature to whole app.</p><p>I also will refactor each column to a new component called TaskList. TaskList will act as a sortable column with the help of SortableContext component. For the data, it will be passed through as a props for TaskList.</p><p>Next, each of the task item will also be refactored to a new component called TaskItem. TaskItem will act as a Sortable Item with the help of useSortable hook. After that, TaskItem can be dragged around freely.</p><p>After that, we can add reorder task list logic to onDragEnd event in DndContext. The task item will be reordered based on the end target position when dropped in.</p><p>If you don’t understand any of these, you can learn about the basic of dnd-kit by reading my first dnd-kit post <a href="https://medium.com/@kurniawancristianto/implement-drag-and-drop-feature-in-react-js-using-dnd-kit-library-4cbd7e4b8135">here</a> and learn about making a sortable list from my guide <a href="https://medium.com/@kurniawancristianto/create-sortable-drag-and-drop-in-react-js-using-dnd-kit-library-ba8b2917a6b5">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5mi-1z85oI7oFwfv5pWfcw.png" /><figcaption>TaskItem.tsx</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NSqIgzaanPVtgb3k3G9XvQ.png" /><figcaption>TaskList.tsx</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*magTzo5lhCmKASRzhq4GaQ.png" /><figcaption>App.tsx</figcaption></figure><p>After all of that, the task item on each column will be draggable and can be reordered when we drag and drop it to a new position. We successfully created a simple drag and drop in one column. Next, we will start implementing drag and drop feature for moving to another column.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*275_zwM3AdHwTBsBt1VJkQ.gif" /><figcaption>Single Column Only Drag and Drop</figcaption></figure><p>To implement multiple column drag and drop, we can create and attach a function for dragOver event provided by DndContext.</p><p>The dragOver event will fires when the item is being clicked and dragged around. In this function, we will have multiple conditions :</p><ol><li>If the item is being dragged into a different column, then we must add that item to that column data, and remove item from it’s column data</li><li>If the item is being dragged around in it’s own column, then we just reorder the column item list order (same with in dragEnd handler)</li></ol><p>We also add a droppable in SortableContext to act as a fixed zone that wrap the whole list area. When the list is empty, user can still drag item from another sortable list to add to that empty sortable list.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6wVVsvAETGZ-LOh96RQuiA.png" /><figcaption>TaskList.tsx (with added Droppable in &lt;ul&gt; element)</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3I9vPP5BSYWBEqOYBerpAw.png" /><figcaption>App.tsx (with added onDragOver event handler)</figcaption></figure><p>With all of that being done, we successfully created a simple multi-column drag-and-drop app with <em>dnd-kit</em> library. In final preview, i added a little CSS for showing the droppable zone and add another column to show more of it’s functionality. With this implementation, you can start build your own Trello task board !</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*t2DPGQn0wMLq8a2fOxpbqA.gif" /><figcaption>Final App Preview</figcaption></figure><p>You can view the full source code in my Github repository : <a href="https://github.com/WawanC/multi-column-dnd-kit">https://github.com/WawanC/multi-column-dnd-kit</a></p><p>Thank you for reading this guide. You can follow me if you interested in more content like this.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2acd9a65fab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create sortable drag and drop in React JS using dnd-kit library]]></title>
            <link>https://medium.com/@kurniawanc/create-sortable-drag-and-drop-in-react-js-using-dnd-kit-library-ba8b2917a6b5?source=rss-3ce190be97c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba8b2917a6b5</guid>
            <category><![CDATA[javascript-library]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Kurniawan Cristianto]]></dc:creator>
            <pubDate>Sat, 18 Feb 2023 07:50:06 GMT</pubDate>
            <atom:updated>2023-02-18T07:50:06.680Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*W74HOe5IJ1P3iZ4j.png" /><figcaption>dnd-kit</figcaption></figure><p>On previous article, i already created a guide about how to implement simple drag and drop interface in React JS using <em>dnd-kit</em> library (<a href="https://dndkit.com/">https://dndkit.com</a>). You can view the previous guide <a href="https://medium.com/@kurniawancristianto/implement-drag-and-drop-feature-in-react-js-using-dnd-kit-library-4cbd7e4b8135">here</a>.</p><p>Today, we are going a bit further by implementing drag and drop feature that can be sorted (sortable). <em>dnd-kit </em>library provides this feature by using Sortable component.</p><p>In this guide, we will create a simple app that display list of favorite games and each of the game can be dragged around to represent the ranking of the favorite games based on their order.</p><p>In this project, i will use following technologies :</p><ul><li>React JS for UI library</li><li>Typescript for language</li><li>CSS Modules for styling</li><li><em>dnd-kit </em>to implement drag and drop feature</li></ul><p>First, i will start by creating an empty React JS project and creating basic initial view for the games list. You can also implement this feature on your existing project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*588hSnRB04lZCrlDPKF1Mw.png" /><figcaption>Project Files Structure</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uqPFw62_yVd3D3RWlCIFtQ.png" /><figcaption>App.tsx</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QzIyvoU8eu8u8Nb3V5Ah4A.png" /><figcaption>Initial App Preview</figcaption></figure><p>Then, to implement drag and drop feature we can install dnd-kit library by using command :</p><p><em>npm install @dnd-kit/core</em></p><p>We also must install additional package from dnd-kit to implement sortable feature using command :</p><p><em>npm install @dnd-kit/sortable</em></p><p>Like previous guide, we need to wrap our components that need the drag and drop feature inside of DndContext component (in this case, all of our App component). To implement sortable list feature, we also need to use the SortableContext component to wrap all of our sortable list and provide the items props with the list data.</p><p>We also need to use state for the list data so it have the reactivity and change the list when the order changed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9cqaAMmu4GQnEV3786kOAw.png" /><figcaption>App.tsx</figcaption></figure><p>After that, we can create the Sortable Item component by using useSortable hook (in this case, each of the game list item). useSortable hook combines both useDroppable and useDraggable hook, so it can be act as a draggable item and also as a droppable zone.</p><p>useSortable hook provides data such as attributes, listeners, setNodeRef to make an element become Sortable Item. It also provides transform and transition CSS property value so it can be dragged around and have nice reordering animation. Like in Draggable component, we can use additional CSS utility class provided by <em>dnd-kit</em> to change the transform variable to CSS property value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eBc-2nWylXt1AsGeOuoLGQ.png" /><figcaption>GameItem.tsx</figcaption></figure><p>Next, we can start using the Sortable Item inside SortableContext in App component. We need to restructure the element that wrap the list (in this case, the &lt;ul&gt; element) to outside of the SortableContext so the context is directly in touch with the Sortable Item.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*54f8uGBXUM79uF6uJvS6qA.png" /><figcaption>App.tsx</figcaption></figure><p>Finally, we can start implementing the sortable drag and drop feature by adding logic inside onDragEnd event handle provided by DndContext. In this case, i will create a function to reorder the games list when one of the game have been dragged to a new position. dnd-kit library also provides arrayMove() function to simplify the process or reordering the array elements.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ATHL6QCuuoLChCKB3UJr2A.png" /><figcaption>App.tsx</figcaption></figure><p>At last, the app is complete and we can drag the game item around. When game item is dropped to new position, the Sortable List will automatically re-sort the list items based on the new position. It also provides nice and beautiful animation when items are reordered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*9YgqtQYrX7AFQrjp93gKgQ.gif" /><figcaption>Final App Demo</figcaption></figure><p>You can view the full source code in my Github repository : <a href="https://github.com/WawanC/react-dnd-kit-sortable">https://github.com/WawanC/react-dnd-kit-sortable</a></p><p>Thank you for reading and you can follow me to read another post about React JS.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba8b2917a6b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Implement drag and drop feature in React JS using dnd-kit library]]></title>
            <link>https://medium.com/@kurniawanc/implement-drag-and-drop-feature-in-react-js-using-dnd-kit-library-4cbd7e4b8135?source=rss-3ce190be97c4------2</link>
            <guid isPermaLink="false">https://medium.com/p/4cbd7e4b8135</guid>
            <category><![CDATA[javascript-library]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Kurniawan Cristianto]]></dc:creator>
            <pubDate>Fri, 17 Feb 2023 16:23:10 GMT</pubDate>
            <atom:updated>2023-02-18T05:58:02.034Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kpdsfR1Z1tEb28eVdOs6WQ.png" /><figcaption>dnd-kit</figcaption></figure><p>Hi everyone, today i will make guide on how to implement drag and drop feature in React JS using <em>dnd-kit</em> library.</p><p><em>dnd-kit</em> is a React JS library that used to building drag and drop interfaces . <em>dnd-kit</em> has a lot of advantages to offer such as easy-to-use and performance stability. (<a href="https://dndkit.com/">https://dndkit.com</a>)</p><p>In this guide i will show you how to create and implement basic drag and drop interface in React JS using <em>dnd-kit</em>. In this example, i will be creating a simple fruit-cart app. User can add a fruit to the cart by simply dragging and dropping it to cart area.</p><p>In this project, i will use following technologies :</p><ul><li>React JS for UI library</li><li>Typescript for language</li><li>CSS Modules for styling</li><li><em>dnd-kit </em>to implement drag and drop feature</li></ul><p>Let’s begin the guide. First, make sure you have already initialized a new or already have current React JS project.</p><p>I already initialized a new empty React JS project for this guide with following files structure :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/514/1*Vxyh-I6_GoAe2GzTBX0spg.png" /><figcaption>Initial Project File Structure</figcaption></figure><p>Next, i will add initial fruits data on App.tsx and add basic view for displaying all fruits item in a list to select later and also display cart section along with its box.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Dfz_3uK45Xt3moUI34nYVg.png" /><figcaption>App.tsx</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EDqmLKDJTqJJT-JCwE7Q_w.png" /><figcaption>Initial App Preview</figcaption></figure><p>After creating that basic view, we can start implement the drag and drop feature using <em>dnd-kit</em> library.</p><p>First, you need to install <em>dnd-kit </em>library in project using package manager with command :</p><p><em>npm install </em><a href="http://twitter.com/dnd"><em>@dnd</em></a><em>-kit/core</em></p><p>Then you need to add DndContext component to cover all your other components that needs to implement drag and drop feature (In this case, all components in App.tsx). DndContext allows your draggable components and droppable container to interact with each other.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gFJq9Br4-yAECIo7YojLZw.png" /><figcaption>Add DndContext Component</figcaption></figure><p>Next, we can create a Droppable component. Droppable used as a container and space to detect when the other component has been dragged in. Droppable component also used to display selected data based on what has been dropped in.</p><p>To create Droppable component, we can use useDroppable hook. It requires an unique id (can be any string) to identify it from another droppable. It also returns a function (setNodeRef) to set the component to become Droppable.</p><p>In this case, i will create another component (CartDroppable) to set as a Droppable using useDroppable hook. It also receive an array of string as a props to display the cart items that has been selected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qUcZPCH7bh69yXE8qo3FQw.png" /><figcaption>CartDroppable.tsx</figcaption></figure><p>Then we can import and implement it in App.tsx. I also create a state to hold all the selected cart items and then pass it as a prop to CartDroppable component to later display it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*94p-XFODN6pKlmqquyJ6Ow.png" /><figcaption>App.tsx</figcaption></figure><p>After that we can start creating Draggable component. Draggable act as an object to drag and drop. We can create it using useDraggable hook.</p><p>Same with useDroppable, useDraggable hook also require an unique id (can be any string) to identify it from another Draggable. It also can store data in its data property to used it later in the app.</p><p>useDraggable hook returns many thing such as attributes, listeners, setNodeRef, and transform. Attributes, listeners and setNodeRef is passed to a component to set it as a Draggable. Transform is used to provide information about draggable when it is being moved. We can use CSS utility function provided by <em>dnd-kit </em>library to convert the Transform data to string (as transform css property value) and then use it to style the Draggable component (so it can be moved around because of transform css property).</p><p>In this case, I will create a component named FruitDraggable to act as an Draggable. I also set the data to store the fruit item name to used it later. I set up the FruitDraggable based on the information above that i’ve been explained.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WpbtQJn8ohDGPPpA6spBbA.png" /><figcaption>FruitDraggable.tsx</figcaption></figure><p>Next, we can import it in App.tsx and create it with fruit item data. It then can be selected and dragged around.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0Dpit8LJ3P6fD36TCtU3Eg.png" /><figcaption>App.tsx</figcaption></figure><p>Finally we can implement drag and drop feature using onDragEnd event. onDragEnd is one of many event provided in DndContext component that runs when a Draggable is being dropped inside a Droppable. We can use it to change the items inside droppable when a draggable is being dropped in.</p><p>In this case, i will create a function to add selected fruit to the cart when onDragEnd event fires. It also will updated the cart items state and when it updated, the CartDroppable items display will also be updated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4VPR4nUKhshTvWj3hQgO7A.png" /><figcaption>App.tsx</figcaption></figure><p>And that’s it. We successfully implement the drag and drop feature in React JS using <em>dnd-kit</em> library by creating this simple fruit-cart app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*wtRA4792-IBiMh5_R0OJJg.gif" /><figcaption>Final App Demo</figcaption></figure><p>You can view the full source code in my Github repository : <a href="https://github.com/WawanC/react-dnd-kit-basic">https://github.com/WawanC/react-dnd-kit-basic</a></p><p>Thank you for reading and you can follow me to read another post about React JS.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4cbd7e4b8135" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>