<?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: Nikhil Devarasetty</title>
    <description>The latest articles on DEV Community by Nikhil Devarasetty (@nikhildevarasetty).</description>
    <link>https://dev.to/nikhildevarasetty</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%2F805713%2F9fa67bf7-6cd2-4b26-a2af-e8ecbab1821e.jpeg</url>
      <title>DEV Community: Nikhil Devarasetty</title>
      <link>https://dev.to/nikhildevarasetty</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nikhildevarasetty"/>
    <language>en</language>
    <item>
      <title>Understanding Rails Seeds</title>
      <dc:creator>Nikhil Devarasetty</dc:creator>
      <pubDate>Sat, 06 Jan 2024 13:59:27 +0000</pubDate>
      <link>https://dev.to/nikhildevarasetty/understanding-rails-seeds-h33</link>
      <guid>https://dev.to/nikhildevarasetty/understanding-rails-seeds-h33</guid>
      <description>&lt;h2&gt;
  
  
  What Are Seeds?
&lt;/h2&gt;

&lt;p&gt;In a Ruby on Rails application, seeds are used to populate the database with predefined data. This data could include default user accounts, sample products, or any other records required for the application to function correctly. Seeds are especially useful during the development and testing phases, allowing developers to work with a database that contains meaningful data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configuring Seeds:
&lt;/h2&gt;

&lt;p&gt;Configuring seeds involves creating a file named &lt;strong&gt;seeds.rb&lt;/strong&gt; in the Rails application's db directory. This file contains Ruby code that specifies the data to be inserted into the database. The &lt;strong&gt;seeds.rb&lt;/strong&gt; file is structured similarly to a Rails migration file but is focused on data rather than schema changes.&lt;/p&gt;

&lt;p&gt;To run the seeds and populate the database, use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails db:seed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to Use Seeds:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Create the &lt;strong&gt;seeds.rb&lt;/strong&gt; File:
&lt;/h3&gt;

&lt;p&gt;Start by creating the &lt;strong&gt;seeds.rb&lt;/strong&gt; file in the db directory of your Rails application.&lt;/p&gt;

&lt;h3&gt;
  
  
  Write Seed Data:
&lt;/h3&gt;

&lt;p&gt;Inside &lt;strong&gt;seeds.rb&lt;/strong&gt;, use Ruby code to define the data you want to insert. This may include creating instances of ActiveRecord models and populating their attributes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# db/seeds.rb

User.create(username: 'admin', email: 'admin@example.com', password: 'password')
Product.create(name: 'Sample Product', price: 19.99, description: 'A description of the product.')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Run the Seeds:
&lt;/h3&gt;

&lt;p&gt;Execute the following command to populate the database with the defined seed data:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails db:seed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Other commands to work around:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Generate Seeds File:&lt;/strong&gt; To create a new seeds file (users_seeds.rb), you can use the following command:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails generate seed users_seed.rb
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will generate an empty &lt;strong&gt;db/users_seed.rb&lt;/strong&gt; file if it doesn't exist.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Run Seeds:&lt;/strong&gt; To execute the seeds and populate the database with the defined data in the seeds.rb file, use:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails db:seed
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will run the code inside the &lt;strong&gt;seeds.rb&lt;/strong&gt; file, creating records in the database.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Reset and Seed Database:&lt;/strong&gt; If you want to reset the database (drop, create, and migrate) and then run the seeds, you can use the following command:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails db:reset
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command is helpful during development when you need to recreate the database with the latest schema and seed data.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Specific Seed File:&lt;/strong&gt; If you have multiple seed files or a custom seed file, you can specify the file to run:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails db:seed:custom_seeds
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;strong&gt;custom_seeds&lt;/strong&gt; with the actual filename you want to execute.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Loading Seed Data in Development Environment:&lt;/strong&gt; During development, you might want to run seeds frequently. You can use the following command to load the seeds:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails db:seed RAILS_ENV=development
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Running Custom Seed Tasks:&lt;/strong&gt; You can create custom seed tasks in your &lt;strong&gt;lib/tasks&lt;/strong&gt; directory and run them using:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails db:seed:custom_task
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example &lt;strong&gt;lib/tasks/custom_seed.rake&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;namespace :db do
  namespace :seed do
    desc 'Custom seed task'
    task custom_task: :environment do
      # Your custom seed logic
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Pros of Using Seeds:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Consistency:&lt;/strong&gt; Seeds provide a consistent set of initial data for all developers working on the project, ensuring a standardized environment.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Faster Development:&lt;/strong&gt; Seeds help developers set up a working database quickly, saving time during the development process.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Testing:&lt;/strong&gt; Seeds are invaluable for testing, allowing developers to create predictable scenarios and reproduce specific conditions for testing purposes.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Cons of Using Seeds:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Static Data:&lt;/strong&gt; Seeds provide static data that might not evolve with changes in the application. Developers need to update seeds manually when the data model changes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Security Concerns:&lt;/strong&gt; Care must be taken not to include sensitive information in seed data, especially if the seeds file is committed to version control.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Maintenance Overhead:&lt;/strong&gt; As the application evolves, maintaining and updating seed data may become a task, especially in larger projects.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Creating Chat Bot in Slack</title>
      <dc:creator>Nikhil Devarasetty</dc:creator>
      <pubDate>Sun, 10 Jul 2022 11:06:41 +0000</pubDate>
      <link>https://dev.to/nikhildevarasetty/creating-chat-bot-in-slack-467o</link>
      <guid>https://dev.to/nikhildevarasetty/creating-chat-bot-in-slack-467o</guid>
      <description>&lt;h2&gt;
  
  
  What is bot? (from slack)
&lt;/h2&gt;

&lt;p&gt;A bot is the same as a regular app: it can access the same range of APIs and do all of the magical things that a Slack App can do.&lt;/p&gt;

&lt;p&gt;But when you build a bot for your Slack App, you're giving that app a face, a name, and a personality, and encouraging users to talk to it.&lt;/p&gt;

&lt;p&gt;Your bot can send DMs, it can be mentioned by users, it can post messages or upload files, and it can be invited to channels - or kicked out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating a bot:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Create a slack app choosing the workspace.&lt;/li&gt;
&lt;li&gt;Then navigate to the created app and add bot permissions under &lt;code&gt;OAuth &amp;amp; permissions&lt;/code&gt;, it will automatically create a bot user.&lt;/li&gt;
&lt;li&gt;Hurray! your slack bot is created.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Users need to install the app to use it's bot features&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Installing app:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;App can be distributed publicly for users to install it from slack app directory.&lt;/li&gt;
&lt;li&gt;App can also be installed through slack &lt;a href="https://api.slack.com/authentication/oauth-v2#asking"&gt;OAuth flow&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Bot features:
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Webhooks:
&lt;/h3&gt;

&lt;p&gt;We can create webhook urls for a channel or user of the team and can use the webook url to post messages to selected target.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Slash commands:
&lt;/h3&gt;

&lt;p&gt;With slash commands we provide utilities to interact with bot.&lt;br&gt;
Ex: /get-users-list, and provided redirect url which handles the commands request and sends payload.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Events:
&lt;/h3&gt;

&lt;p&gt;We can subscribe to the events provided by slack and upon triggering we can handle it with provided redirect url.&lt;br&gt;
Ex: team-join, user_change...&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;To enable user interactivity with bot enable &lt;code&gt;Allow users to send Slash commands and messages from the messages tab&lt;/code&gt; under &lt;code&gt;App Home&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;With slack block kit we can create interactive forms, surveys, send formatted messages, and more. Explore &lt;a href="https://api.slack.com/block-kit"&gt;slack block-kit&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
    </item>
    <item>
      <title>Getting started with SSR in Reactjs</title>
      <dc:creator>Nikhil Devarasetty</dc:creator>
      <pubDate>Mon, 23 May 2022 05:58:15 +0000</pubDate>
      <link>https://dev.to/nikhildevarasetty/getting-started-with-ssr-in-reactjs-lh8</link>
      <guid>https://dev.to/nikhildevarasetty/getting-started-with-ssr-in-reactjs-lh8</guid>
      <description>&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Server side rendering or SSR&lt;/strong&gt; is a technique to build fully rendered HTML page in the server side, which is then travels through network and gets rendered in the client side browser.&lt;br&gt;
Conventionally server submits an empty index.html page which have build script in a script tag to the client’s initial request and then javascript start’s its part where it builds index.html page or renders the components to index.html and for consecutive navigations.&lt;/p&gt;




&lt;h3&gt;
  
  
  why SSR? 🤔
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Loads pages faster which results in better user experience&lt;/strong&gt;&lt;br&gt;
Ideally on client’s initial request it gets an empty index.html page, then javascript tries to render components to it.&lt;br&gt;
Assume that the initial page consisting of complex components need to rendered with server data as it will be slow and user need to wait the whole time while page is being rendered.&lt;br&gt;
In which SSR comes into scene in providing fully rendered pages with server data(no external api call required as it is taking place in server) which is fast.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Content is rendered before initial page load which is SEO friendly&lt;/strong&gt;&lt;br&gt;
Old ways of SEO includes adding meta information title and description to the page so that they are indexed according to the content in title and description.&lt;br&gt;
Search engines no longer gives any points to it.&lt;br&gt;
So when a fully rendered page is being served, the search engine crawls over the content and index the web pages in a better way.&lt;br&gt;
By this content in page contributes to the better index.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;Rendering server-side may be ideal for initial static site generation, but frequent server requests and full page reloads for all consecutive navigations can result in overall slower page rendering in more complex applications.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h3&gt;
  
  
  Steps to initiate SSR in React app:
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Creating new project with create-react-app skipped here&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step 1 - Modify index.js file in src directory:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhc1xgi01h8lktnfpza4s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhc1xgi01h8lktnfpza4s.png" alt="index.js file code" width="662" height="614"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ReactDOM.render&lt;/strong&gt; is changed to ReactDOM.hydrate in index.js file, hydrate method is same as render but it indicates ReactDOM to hydrate the server-side rendered content&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 2 - Create express server and render app component on initial request:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzcgww5f1fpqsk75gbzs6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzcgww5f1fpqsk75gbzs6.png" alt="server code" width="800" height="845"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;App component is imported and converted static html string and this static content with rendered React components which is attached to div with id root returned as string in response.&lt;br&gt;
This fully rendered page is hydrated to DOM on client side.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step 3 - webpack configuration:&lt;/strong&gt;&lt;br&gt;
Create a file with name webpack.server.js&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4ogmofcvkqktzdeeh6a9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4ogmofcvkqktzdeeh6a9.png" alt="webpack.server.js code" width="800" height="721"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Use of target: ‘node’ and externals: [nodeExternals()] avoid including node-module files in bundle as server directly access them.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;SSR can be implemented using Nextjs framework which is build on top of React library which provides different SSR techniques like SSG, SSR and ISR.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Each technique generates a fully rendered html page with required data(no external api calls needed) and send it to client on initial request.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Server side rendering or SSR:&lt;/strong&gt;&lt;br&gt;
One need to navigate to the page to get server rendered page and whenever the page is visited again, page is build in server again and sent it to client.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Static site generation or SSG:&lt;/strong&gt;&lt;br&gt;
One need to navigate to the page to get server rendered page and on consecutive visits to the page will not be re-rendered in server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Incremental static regeneration or ISR:&lt;/strong&gt;&lt;br&gt;
One need to navigate to the page to get server rendered page and the page will be re-rendered in the server, will be sent to client on defined time interval.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Handful Hooks</title>
      <dc:creator>Nikhil Devarasetty</dc:creator>
      <pubDate>Sun, 22 May 2022 17:32:38 +0000</pubDate>
      <link>https://dev.to/nikhildevarasetty/handful-hooks-38kl</link>
      <guid>https://dev.to/nikhildevarasetty/handful-hooks-38kl</guid>
      <description>&lt;p&gt;Hooks are backward-compatible, which are introduced in React16.8, it makes use of state and other react features without writing class components.&lt;/p&gt;

&lt;p&gt;It does not introduce new concepts, helps in writing simplified and more understandable code implementing existing concepts.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Conventionally functional components are used for representational purposes, referred to as dumb or stateless components, but with the introduction of Hooks, we can implement all class-based components concepts with functional components.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;🤔 Ever faced a situation where for earlier requirements you have implemented functional component, and now you have to implement state in component, provided you would have done it by converting it into the class component.&lt;/p&gt;

&lt;p&gt;😇 Now simply just use Hooks to implement state in functional components.&lt;/p&gt;

&lt;p&gt;There are Handful of Hooks which are handy and can improve the way of coding, which I will introduce in a bit.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Hooks?
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Complex components with side effects:&lt;/strong&gt;
components are easy to understand and build at the start 
but growing stateful logic and side-effects including 
fetching data makes it harder to understand and maintain, 
while hooks make it easy by decoupling the logic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Classes confuses a lot:&lt;/strong&gt;
while implementing class-based components you should have 
known how to use this, scope, different life-cycle methods, 
and their use-cases. Every time you refer to a function in 
class component you should have bound it with this(class 
context) to the function in the constructor or call it with 
&lt;code&gt;this&lt;/code&gt; context.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clean and neet code:&lt;/strong&gt;
with Hooks, all class-based life-cycle and state management 
can be implemented in functional components and easy to de- 
couple the logic with Hooks. We can implement the same 
logic with functional components in fewer lines.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Hooks
&lt;/h2&gt;

&lt;p&gt;Basic hooks which need to have look at when getting started with are &lt;strong&gt;useState&lt;/strong&gt; and &lt;strong&gt;useEffect&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With &lt;strong&gt;useState&lt;/strong&gt; we can implement state management in functional components, syntax is likely&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3aa69pxwni45coemjplh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3aa69pxwni45coemjplh.png" alt="useState hook implementation code" width="800" height="541"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;useState&lt;/strong&gt; returns two arguments, state variable, and state setter. &lt;/li&gt;
&lt;li&gt;With &lt;strong&gt;useState&lt;/strong&gt;, we can use any number of state variables.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Recommended way of setting state is:
setState(preState =&amp;gt; {
   //use preState to create new state
   return newState
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;useEffect&lt;/strong&gt; is another common Hook that can be used to implement class-based life-cycle methods like &lt;strong&gt;ComponentDidMount&lt;/strong&gt; and &lt;strong&gt;ComponentDidUpdate&lt;/strong&gt;. It also has a clean-up callback which is executed before every respective useEffect call.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;useEffect&lt;/strong&gt; accept args array which is trigger useEffect on change of args in array, if given empty array only triggers at mounting&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  useRef:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;useRef&lt;/strong&gt; can be used to refer Dom elements and can be used to create static content.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const ref = useRef(intialValue) and refered by ref.current
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  useMemo and useCallback:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;useMemo&lt;/strong&gt; and &lt;strong&gt;useCallback&lt;/strong&gt; are memoization purpose hooks, which also accept args array, trigger upon any args in array changes. Mainly used for computing expensive calculations and avoid doing it on re-renders.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ucwpn3rgqsorithdu43.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1ucwpn3rgqsorithdu43.png" alt="useMemo and useCallback implementation code" width="800" height="918"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  useContext and useReducer:
&lt;/h3&gt;

&lt;p&gt;context Api can be implemented by using &lt;strong&gt;useContext&lt;/strong&gt;, &lt;strong&gt;useContext&lt;/strong&gt; will helps in consuming context value coming from the parent(context is created using React.createContext).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;useReducer&lt;/strong&gt; will help in maintaining complex state management, it works in the same fashion as Redux. We define reducers and dispatch actions to perform a required state change.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Good use-case is using useContext and useReducer together, to create gobal or localised state for component tree. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  React-router-dom Hooks:
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;useParams:&lt;/strong&gt; to extract params from the URL.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;useHistory:&lt;/strong&gt; to use history API in component at any level.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;useLocation:&lt;/strong&gt; provide pathname, match, and location information.&lt;/p&gt;

&lt;h3&gt;
  
  
  React-Redux Hooks:
&lt;/h3&gt;

&lt;p&gt;react-redux provides hooks that make life easy, implementing redux logic using the hooks provided by react-redux is easy to understand and implement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;useDispatcher:&lt;/strong&gt; return a dispatcher which dispatches actions to modify state&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;useSelector:&lt;/strong&gt; to get a slice or select slice of the store from the global store.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;useStore:&lt;/strong&gt; returns the whole store which contains all store slices.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;These are the hooks I feel come in handy and can be used commonly, although there are few other hooks that can be used on-demand. Explanation of each hook can be huge and can’t be done in one page so do explore the above hooks individually✌️&lt;/p&gt;

</description>
    </item>
    <item>
      <title>OAuth with slack</title>
      <dc:creator>Nikhil Devarasetty</dc:creator>
      <pubDate>Sun, 22 May 2022 08:21:53 +0000</pubDate>
      <link>https://dev.to/nikhildevarasetty/oauth-with-slack-3i49</link>
      <guid>https://dev.to/nikhildevarasetty/oauth-with-slack-3i49</guid>
      <description>&lt;p&gt;&lt;strong&gt;🤔 What is OAuth? 👇&lt;/strong&gt;&lt;br&gt;
OAuth is a protocol that lets your app request authorization to private details.&lt;/p&gt;

&lt;p&gt;With slack we can implement OAuth for the required scopes, to access the workspace channels, members, conversations, calls, listen to events, etc...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ohh, 🤔 What are scopes then? 👇&lt;/strong&gt;&lt;br&gt;
Scopes are used to grant your app permission to perform functionality in Slack like,&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Call Web API methods, users.list, channels.read, 
channels.write, etc...&lt;/li&gt;
&lt;li&gt;Receive Events API events like, user joined, channel 
created, etc...&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Then how to do it? 👉 Follow the below steps&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Create and Install app to workspace:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Create slack workspace, by going to &lt;a href="https://dev.tourl"&gt;https://slack.com&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;After that, create an app, by going to &lt;a href="https://dev.tourl"&gt;https://api.slack.com/apps&lt;/a&gt;, choosing respective workspace.&lt;/li&gt;
&lt;li&gt;After creating app, go to the created app and under &lt;code&gt;OAuth &amp;amp; permissions&lt;/code&gt; section give the required scopes.&lt;/li&gt;
&lt;li&gt;After giving scopes you can able to install app to your workspace or publish it to slack open directory.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Performing OAuth
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;To perform OAuth we need to generate authorization redirect url, to do so navigate to &lt;a href="https://dev.tourl"&gt;https://api.slack.com/authentication/sign-in-with-slack&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The url will look like,&lt;br&gt;
&lt;/p&gt;

&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GET /openid/connect/authorize?
 response_type=code
 &amp;amp;scope=openid%20profile%20email
 &amp;amp;client_id=s6BhdRkqt3
 &amp;amp;state=af0ifjsldkj
 &amp;amp;team=T1234
 &amp;amp;nonce=abcd
 &amp;amp;redirect_uri=https%3A%2F%2Fclient.example.org%2Fcb 
HTTP/1.1
Host: https://slack.com
&lt;/code&gt;&lt;/pre&gt;




&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;code&gt;redirect_uri&lt;/code&gt; in above url, is the request handler for which slack to redirect with temporary access code.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;With that temporary access code we need to request for access-token using api &lt;code&gt;slack.com/api/openid.connect.token?code={access_code}&amp;amp;client_id=###&amp;amp;client_secret=###&amp;amp;redirect_uri=###&lt;/code&gt;, for more details about api method, headers and parameter look into &lt;a href="https://dev.tourl"&gt;&lt;/a&gt;&lt;a href="https://api.slack.com/methods/openid.connect.token"&gt;https://api.slack.com/methods/openid.connect.token&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;With the access-token received, you can store it securely and use it whenever required.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Hurray! It's done 😇&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;I have provided basic walkthrough, please do explore &lt;a href="https://dev.tourl"&gt;https://api.slack.com/authentication/basics&lt;/a&gt;, for detailed explanation.&lt;/li&gt;
&lt;li&gt;And explore the Refresh token concept, how to opt for it, refresh the access-token using refresh token.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Preview locally running Rails app in mobile</title>
      <dc:creator>Nikhil Devarasetty</dc:creator>
      <pubDate>Sun, 22 May 2022 05:55:59 +0000</pubDate>
      <link>https://dev.to/nikhildevarasetty/preview-locally-running-rails-app-in-mobile-1ld9</link>
      <guid>https://dev.to/nikhildevarasetty/preview-locally-running-rails-app-in-mobile-1ld9</guid>
      <description>&lt;p&gt;I used to make things that were comfortable for the screen resolution I was using as a novice, but as time went on and I started producing substantial stuff, I realised I needed to construct mobile-first features.&lt;/p&gt;

&lt;p&gt;Of course, Chrome comes with a responsive view and a mobile view, but why do you need to preview in mobile? 🤔 🤔 🤔&lt;/p&gt;

&lt;p&gt;Let say when trying to input something in text fields in mobile, keyboard will pop up, and sticky footer might cover up text fields, which we usually not observe in laptops.&lt;/p&gt;

&lt;p&gt;Cases like above require to preview app in mobile before pushing into production.&lt;/p&gt;

&lt;p&gt;So to preview in the Rails app in mobile follow the steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Make sure your laptop and phone are connected&lt;/li&gt;
&lt;li&gt;Start sever in local with &lt;code&gt;rails s -p 3000 -b  &amp;lt;IPv4 address of network&amp;gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;To get IPv4 address of the network connected

&lt;ul&gt;
&lt;li&gt;Go to &lt;code&gt;settings &amp;gt; netwrok&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Run &lt;code&gt;ipconfig&lt;/code&gt; in command line&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
  </channel>
</rss>
