<?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: Khalid🥑💻</title>
    <description>The latest articles on DEV Community by Khalid🥑💻 (@khalidk799).</description>
    <link>https://dev.to/khalidk799</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%2F815906%2F93a5f92a-8f86-4e02-a3cf-8db6d59cc809.jpg</url>
      <title>DEV Community: Khalid🥑💻</title>
      <link>https://dev.to/khalidk799</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/khalidk799"/>
    <language>en</language>
    <item>
      <title>Environment variables &amp; Its best practices</title>
      <dc:creator>Khalid🥑💻</dc:creator>
      <pubDate>Mon, 12 Sep 2022 09:29:23 +0000</pubDate>
      <link>https://dev.to/khalidk799/environment-variables-its-best-practices-1o1o</link>
      <guid>https://dev.to/khalidk799/environment-variables-its-best-practices-1o1o</guid>
      <description>&lt;p&gt;An environment variable is a variable whose value is set outside the code or the application. This variable contains matters that will affect the functions of the program. The environment variable can be used everywhere, from a Single Page Application to your CLI or shell.&lt;/p&gt;

&lt;p&gt;These variables also configure the application for different environments such as development, testing, staging and production.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why do we need an environment variable?
&lt;/h2&gt;

&lt;p&gt;The most common use of environment variables is to set up different configuration options for different programming environments. Environment variables are also widely used to store API keys and Auth Token or application configurations or something you want to keep away from the public. &lt;/p&gt;

&lt;p&gt;This will help you make your code predictable by keeping the configuration outside the main codebase.&lt;/p&gt;

&lt;h2&gt;
  
  
  Environment variable best practices
&lt;/h2&gt;

&lt;p&gt;When we are talking about handling data, we usually keep extra precautions. Here is a list of best practices you should follow while working with environment variables.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use dotenv/&lt;code&gt;.env&lt;/code&gt; file to manage environment variables
&lt;/h3&gt;

&lt;p&gt;While working with APIs or third-party service providers, you must have seen developers storing the auth-token or the API key in a &lt;code&gt;.env&lt;/code&gt; file.  &lt;/p&gt;

&lt;p&gt;The &lt;code&gt;.env&lt;/code&gt; file is a value or variable that will help you configure a value in your codebase from outside the application. You can consider this a vault for all your secret or “shhh” keys.&lt;/p&gt;

&lt;p&gt;We usually do not expose the data inside the &lt;code&gt;.env&lt;/code&gt; file to the public for security reasons. &lt;/p&gt;

&lt;p&gt;Let us understand this with an example; consider yourself making a discord bot; you must store the auth token somewhere not accessible to the public. In that case, the easiest way to do so is to keep it in an environment variable.&lt;/p&gt;

&lt;p&gt;Look at this code snippet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nx"&gt;bot_secret_token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ODI3NzczNzY0NTk4NDk3MzIx.YGf6ZA.0_BG9GFQto4aNwg1idPkHHVMwGY&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of doing this, we can do something secure and away from the public. So we will store the auth token in a &lt;code&gt;.env&lt;/code&gt; file and then call it in the main code.&lt;/p&gt;

&lt;p&gt;Here is how we do add the token in an env file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DISCORD_BOT_SECRET= “ODI3NzczNzY0NTk4NDk3MzIx.YGf6ZA.0_BG9GFQto4aNwg1idPkHHVMwGY”

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let us call the token in the main code base,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;bot_secret_token = process.env.DISCORD_BOT_SECRET
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is as simple as storing all your passwords over the cloud and calling the unique key to access the password every time. &lt;/p&gt;

&lt;h3&gt;
  
  
  Do not push the &lt;code&gt;.env&lt;/code&gt; file to your Git Repo
&lt;/h3&gt;

&lt;p&gt;This is the most common mistake; folks usually push the environment variables to their GitHub, exposing the key to the world. Some folks hunt these mistakenly pushed environment variables on Github/Gitlab and use them illegally to access your data. &lt;/p&gt;

&lt;p&gt;This issue can be avoided by adding the &lt;code&gt;.env&lt;/code&gt; file to your existing  &lt;code&gt;.gitignore&lt;/code&gt; file or creating a new one at the root of your repository and adding the .env filename as a new line. Following is the code snippet as an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Inside .gitignore
.env
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If in case the &lt;code&gt;.env&lt;/code&gt; file still shows up in your git repo, it can be removed using the below command in your CLI:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;git rm -r --cached .env&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Use encryption and decryption on environment variables
&lt;/h3&gt;

&lt;p&gt;You might use the &lt;code&gt;.env&lt;/code&gt; file, which sits inside a server, to store important passwords and keys to databases and APIs. Keeping it in text inside a &lt;code&gt;.env&lt;/code&gt; is risky as it may get exposed if the server is compromised. To avoid this issue, one should use Encryption and Decryption. There are a couple of tools and libraries which offer similar functionality. You can try any of those, but we recommend using &lt;a href="https://github.com/brix/crypto-js" rel="noopener noreferrer"&gt;CryptoJS&lt;/a&gt; or &lt;a href="https://github.com/digitalbazaar/forge" rel="noopener noreferrer"&gt;Forge&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Here is how you can encrypt your password using CryptoJS&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;CryptoJS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;crypto-js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;password&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;encrypted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;CryptoJS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;AES&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encrypt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;my-secret&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;encrypted&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After you have encrypted the string, copy and paste it to the &lt;code&gt;.env&lt;/code&gt; file. &lt;/p&gt;

&lt;p&gt;It can be easily decrypted using the below code snippet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;decrypted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;CryptoJS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;AES&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;decrypt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PASS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;my-secret&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;object&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;decrypted&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;CryptoJS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;enc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Utf8&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It can be decrypted if the secret key matches like JWT.&lt;/p&gt;

&lt;p&gt;Suppose you are still unsure about the security. In that case, Some services like Azure have special services like &lt;a href="https://docs.microsoft.com/en-us/azure/devops/pipelines/release/azure-key-vault?view=azure-devops&amp;amp;tabs=yaml" rel="noopener noreferrer"&gt;Azure Key Vault&lt;/a&gt;, where the keys are encrypted and can be injected into the project via a CI/CD or a dev-ops build or directly into VPS or app service.&lt;/p&gt;

&lt;h3&gt;
  
  
  Use the same variable for the different application environments
&lt;/h3&gt;

&lt;p&gt;It is ultimately an optional practice to do so, but we recommend using the same name for the environment variable, even for different application environments.&lt;/p&gt;

&lt;p&gt;For example, if you have &lt;code&gt;My_Sec_token = “Xyz”&lt;/code&gt;, it should be the same for the development, testing, staging and production, Although the values may differ in each case. The reason is - Your code will probably run over different machines for different stages. This will simplify your code and make it easy to use.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;In this blog post, we understood what environment variables are, why they are helpful, and the best practices to keep in mind while using them.&lt;br&gt;
Here are some additional tips you should follow for better use of environment variable:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Do not share your environment variables &lt;/li&gt;
&lt;li&gt;Do not keep the variables inside your code&lt;/li&gt;
&lt;li&gt;Use a secure vault for encryption and decryption of your secret information &lt;/li&gt;
&lt;li&gt;Do not commit your environment variables to version controls like git.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>env</category>
      <category>dotenv</category>
      <category>api</category>
      <category>security</category>
    </item>
    <item>
      <title>Best 10 Code Snippets for Next and JavaScript in 2022</title>
      <dc:creator>Khalid🥑💻</dc:creator>
      <pubDate>Thu, 24 Mar 2022 13:35:29 +0000</pubDate>
      <link>https://dev.to/khalidk799/best-10-code-snippets-for-next-and-javascript-in-2022-2f0a</link>
      <guid>https://dev.to/khalidk799/best-10-code-snippets-for-next-and-javascript-in-2022-2f0a</guid>
      <description>&lt;h1&gt;
  
  
  What is a Code Snippet?
&lt;/h1&gt;

&lt;p&gt;A Code Snippet is a reusable block of code .It is good to reuse code as it will improve your productivity and make sure you always import the correct code and are not missing anything related to code.&lt;/p&gt;

&lt;h1&gt;
  
  
  Why use Code Snippet for Next and JavaScript?
&lt;/h1&gt;

&lt;p&gt;Next.js gives you the best developer experience with all the features you need for production-level applications. To provide a better developer experience and to write better code, faster developers should try to use code snippets while coding.&lt;/p&gt;

&lt;h1&gt;
  
  
  1. Next JS Page Template
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0p62evs7xs196jrn3oca.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0p62evs7xs196jrn3oca.jpeg" alt=" Next JS Page Template" width="377" height="269"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Shortcut:&lt;code&gt;next.page.create&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This code snippet will give users a pre-defined layout for the Next JS Page. This is very beneficial when you are working on multipage applications.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.snipt.dev/snippet/javascript/nextjs-page/5196" rel="noopener noreferrer"&gt;Link to this snippet on Snipt.dev&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  2. Import image using Code Snippets
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fquhe5vuti2vc4zdxp501.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fquhe5vuti2vc4zdxp501.jpeg" alt="Next Image" width="534" height="245"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Shortcut:&lt;code&gt;next.image.create&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This code snippet is an Image component for Next in javascript. You will have to enter the src and some basic alignment, and your image is imported.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.snipt.dev/snippet/javascript/next-image/5209" rel="noopener noreferrer"&gt;Link to this snippet on Snipt.dev&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  3. Hyperlink
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpfm1ia0t03wdy1y7ix8p.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpfm1ia0t03wdy1y7ix8p.jpeg" alt="next Link" width="420" height="293"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Shortcut:&lt;code&gt;next.link.create&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Another helpful code snippet when working with multipage applications. This code snippet will let you import a link component directly onto your IDE.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.snipt.dev/snippet/javascript/next-link/5202" rel="noopener noreferrer"&gt;Link to this snippet on Snipt.dev&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  4. Next App with layout
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F561ij37sxcar3uawxnqg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F561ij37sxcar3uawxnqg.jpeg" alt="Next app with layout" width="684" height="341"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Shortcut:&lt;code&gt;next.app.layout.create&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can directly import your app layout into a page using this code snippet. This code creates an example &lt;code&gt;_app.jsx&lt;/code&gt; with per-page layout capabilities.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.snipt.dev/snippet/javascript/next-app-with-layout/5208" rel="noopener noreferrer"&gt;Link to this snippet on snipt.dev&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  5. Next page with getServerSideProps
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi5hff3snh5wxezsuuya7.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi5hff3snh5wxezsuuya7.jpeg" alt="Next page with getServerSideProps" width="552" height="365"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Shortcut:&lt;code&gt;next.page.server.props.create&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This code snippet will pre-render this page on each request using the data returned by getServerSideProps. This is a helpful code snippet as it will help you code faster, which is the need of the hour.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.snipt.dev/snippet/javascript/next-page-with-getserversideprops/5201" rel="noopener noreferrer"&gt;Link to this snippet on Snipt.dev&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  6. Next useState
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fofm5ez42hc8qul4c0sg6.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fofm5ez42hc8qul4c0sg6.jpeg" alt="Next useState" width="719" height="245"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Shortcut:&lt;code&gt;next.hook.state.use&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This code snippet will help you in state management. The useState Hook allows you to track state in a function component. Need no trouble, right? Just use &lt;code&gt;next.hook.state.use&lt;/code&gt; on your IDE.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.snipt.dev/snippet/javascript/next-usestate/5210" rel="noopener noreferrer"&gt;Link to this snippet on Snipt.dev&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  7. Next getStaticProps
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpd7inl2tqzxdp7l9jght.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpd7inl2tqzxdp7l9jght.jpeg" alt="Image description" width="517" height="293"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Shortcut:&lt;code&gt;next.static.props.create&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Next.js&lt;/code&gt; allows you to export an async function called getStaticProps from the same file. This code snippet has a  function that gets called at build time and lets you pass fetched data to the page's props on pre-rendering.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.snipt.dev/snippet/javascript/next-page-with-getstaticprops/5197" rel="noopener noreferrer"&gt;Link to this snippet on Snipt.dev&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  8. Next getStaticPaths
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3qr20pvvq7r4q2n6h89q.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3qr20pvvq7r4q2n6h89q.jpeg" alt="Image description" width="517" height="293"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Shortcut:&lt;code&gt;next.static.paths.create&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To handle pre-rendered paths on external data. &lt;code&gt;Next.js&lt;/code&gt; lets you export an async function called getStaticPaths from a dynamic page. This code snippet has a function that gets called at build time and enables you to specify which paths you want to pre-render.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.snipt.dev/snippet/javascript/next-getstaticpaths/5199" rel="noopener noreferrer"&gt;Link to this snippet on Snipt.dev&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  9. Next page with getStaticProps
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fanchf52ygq4j6b7a39zb.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fanchf52ygq4j6b7a39zb.jpeg" alt="Image description" width="517" height="413"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Shortcut:&lt;code&gt;next.page.static.create&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This code snippet allows you to create a Next page with static-dynamic props using getStaticProps function.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.snipt.dev/snippet/javascript/next-page-with-getstaticprops/5197" rel="noopener noreferrer"&gt;Link to this snippet on Snipt.dev&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  10. Next create context with hook
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5qb2kqbpvj1q7ya4249q.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5qb2kqbpvj1q7ya4249q.jpeg" alt="Image description" width="614" height="677"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Shortcut: &lt;code&gt;next.context.provider.hook.create&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The code snippet creates a context and a function that takes a context as an argument. The context defines the global scope for the function. The function uses the context to access the value of the &lt;code&gt;val&lt;/code&gt; variable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.snipt.dev/snippet/javascript/next-create-context-with-hook/5216" rel="noopener noreferrer"&gt;Link to this snippet on Snipt.dev&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  How to add your Code Snippet?
&lt;/h1&gt;

&lt;p&gt;Users can add their code snippets and share them with the community using snipt.dev and the Codiga snippet engine. Create an account on app.codiga.io, log in and create your recipe and it will automatically add to snipt.dev&lt;/p&gt;

&lt;p&gt;There are two privacy settings for recipes; make sure you keep the public so that it can be picked by Codiga snippet engine.&lt;/p&gt;

&lt;h1&gt;
  
  
  Developer Resources
&lt;/h1&gt;

&lt;p&gt;Code Snippets search engine &lt;a href="https://www.snipt.dev/" rel="noopener noreferrer"&gt;snipt.dev&lt;/a&gt; for searching and finding some reusable code.&lt;/p&gt;

&lt;p&gt;Please refer to our &lt;a href="https://dev.toCodiga%20Documentation"&gt;official documentation&lt;/a&gt; if you have any doubts.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.codiga.io/" rel="noopener noreferrer"&gt;Codiga&lt;/a&gt; for defining your own code snippets&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>codesnippets</category>
    </item>
  </channel>
</rss>
