<?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: Mark Okhman</title>
    <description>The latest articles on DEV Community by Mark Okhman (@markokhman).</description>
    <link>https://dev.to/markokhman</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%2F625207%2F1cfa4376-60d5-4eee-9a8e-1d8896a3cf27.jpeg</url>
      <title>DEV Community: Mark Okhman</title>
      <link>https://dev.to/markokhman</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/markokhman"/>
    <language>en</language>
    <item>
      <title>Using DeLab Connect with Next.js</title>
      <dc:creator>Mark Okhman</dc:creator>
      <pubDate>Sat, 12 Nov 2022 10:02:48 +0000</pubDate>
      <link>https://dev.to/markokhman/using-delab-connect-with-nextjs-52j7</link>
      <guid>https://dev.to/markokhman/using-delab-connect-with-nextjs-52j7</guid>
      <description>&lt;p&gt;Recently I've seen a release of an awesome repository enabling single-page React apps to seamlessly integrate authentication with a number of TON wallets.&lt;/p&gt;

&lt;p&gt;Kudos to DeLab team ❤️&lt;br&gt;
&lt;a href="https://github.com/delab-team/connect"&gt;https://github.com/delab-team/connect&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I plan to record a video soon where I will go into more detail on when this is a good lib to use and when we should go with the standard "per-wallet" authentication approach. Subscribe to my Telegram channel if you don't want to miss it &lt;a href="https://t.me/markokhmandev"&gt;https://t.me/markokhmandev&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Because I'm using Next.js for most of my web projects, I've run into some issues using DeLab Connect. However, a single React hook solves those issues. This hook makes sure that we are importing the DeLab Connect only on the client side. Furthermore, our hook has an interface (connectInfo and callbacks) to interact with the DeLab Connect instance.&lt;/p&gt;

&lt;p&gt;Before we get to the hook's code, let's do some preparation. You will need to prepare the delab's module before passing it to Next.js. For this you need two things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install &lt;code&gt;next-transpile-modules&lt;/code&gt;:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn add next-transpile-modules
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Replace default next.config.js with following code:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
};
const withTM = require("next-transpile-modules")(["@delab-team/connect"]); // pass the modules you would like to see transpiled
module.exports = withTM(nextConfig);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now we are good to go with the Hook's code:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;You can place this hook anywhere in your project (ex. &lt;code&gt;/shared/hooks/useDeLabConnect.ts&lt;/code&gt;) and then import it on your page.&lt;/p&gt;

&lt;h2&gt;
  
  
  How do we use it?
&lt;/h2&gt;

&lt;p&gt;Inside of our page component we are placing the use of our hook:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; const { DeLabConnector, DeLabModal, DeLabButton } = useDeLab({
    connectInfo: {
      url: "https://example.com",
      name: "Example",
      network: "testnet",
    },
    callbacks: {
      onConnect: async (event: DeLabEvent) =&amp;gt; handleConnect(event),
      onDisconnect: () =&amp;gt; {
        console.log("disconect");
      },
      onErrorTransaction: (event: DeLabEvent) =&amp;gt; handleErrorTransaction(event),
      // ... other callbacks handled in our hook
    },
  });
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Our hook returns 3 important instances:&lt;br&gt;
&lt;strong&gt;DeLabConnector&lt;/strong&gt; - of type DeLabConnect, we will use this one to request transactions etc.&lt;br&gt;
&lt;strong&gt;DeLabModal&lt;/strong&gt; &amp;amp; &lt;strong&gt;DeLabButton&lt;/strong&gt; - Elements, we will simply put them on the page &lt;/p&gt;

&lt;p&gt;Here is a full example of our Next.js page using the useDeLabConnect.ts&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;That's it :) Let me know in comments, what you think about this.&lt;br&gt;
And bro, please subscribe to my Telegram channel: &lt;a href="https://t.me/markokhmandev"&gt;https://t.me/markokhmandev&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ton</category>
      <category>nextjs</category>
      <category>delab</category>
      <category>connect</category>
    </item>
  </channel>
</rss>
