{"id":6916,"date":"2023-01-06T04:24:19","date_gmt":"2023-01-06T04:24:19","guid":{"rendered":"https:\/\/www.ardorsys.com\/blog\/?p=6916"},"modified":"2023-01-06T16:51:47","modified_gmt":"2023-01-06T16:51:47","slug":"learn-to-create-tabbing-component-in-next-js-14","status":"publish","type":"post","link":"https:\/\/www.ardorsys.com\/blog\/learn-to-create-tabbing-component-in-next-js-14\/","title":{"rendered":"Learn to Create Tabbing Component in Next.js 14"},"content":{"rendered":"<p>Do you want to create tabbing in Next.JS but don&#8217;t know how to do this? Here are the steps in this blog with an example.<\/p>\n<p>To create a tabbing component in Next.js, you can use the <code>useState<\/code> hook to manage the state of the selected tab and the <code>onClick<\/code> event handler to switch between tabs.<\/p>\n<p>Here is an example of how you might do this:<\/p>\n<pre lang=\"javascript\" escaped=\"true\">import { useState } from 'react';\r\n\r\nfunction ArTabbing() {\r\n  const [activeTab, setActiveTab] = useState(1);\r\n\r\n  return (\r\n    &lt;div&gt;\r\n      &lt;div className=\"tabs\"&gt;\r\n        &lt;button className={activeTab === 1 ? 'active' : ''} onClick={() =&gt; setActiveTab(1)}&gt;\r\n          Tab One\r\n        &lt;\/button&gt;\r\n        &lt;button className={activeTab === 2 ? 'active' : ''} onClick={() =&gt; setActiveTab(2)}&gt;\r\n          Tab Two\r\n        &lt;\/button&gt;\r\n        &lt;button className={activeTab === 3 ? 'active' : ''} onClick={() =&gt; setActiveTab(3)}&gt;\r\n          Tab Three\r\n        &lt;\/button&gt;\r\n      &lt;\/div&gt;\r\n      &lt;div className=\"tab-content\"&gt;\r\n        {activeTab === 1 &amp;&amp; &lt;div&gt;Content of tab One&lt;\/div&gt;}\r\n        {activeTab === 2 &amp;&amp; &lt;div&gt;Content of tab Two&lt;\/div&gt;}\r\n        {activeTab === 3 &amp;&amp; &lt;div&gt;Content of tab Three&lt;\/div&gt;}\r\n      &lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n  );\r\n}\r\n\r\nexport default ArTabbing;\r\n<\/pre>\n<blockquote><p>Read also:\u00a0<a href=\"https:\/\/www.ardorsys.com\/blog\/why-should-your-next-app-combine-a-nodejs-backend-with-a-reactjs-frontend-app\/\" rel=\"bookmark\">Why Should Your Next App Combine a NodeJS Backend With a ReactJS Frontend App?<\/a><\/p><\/blockquote>\n<p>This code defines a <code>ArTabbing<\/code> component that uses the <code>useState<\/code> hook to manage the state of the <code>activeTab<\/code> variable and the <code>onClick<\/code> event handler to switch between tabs. It renders a set of buttons for each tab and uses a ternary operator to apply the <code>active<\/code> class to the button for the currently active tab. It also renders the content for the active tab using a ternary operator to show the content for the selected tab and hide the content for the other tabs.<\/p>\n<p>You can style the tabs and content <a href=\"https:\/\/www.ardorsys.com\/ui-ux-design-services\/\">using CSS<\/a> to create a visually appealing tabbing component.<\/p>\n<h2>Conclusion<\/h2>\n<p>In this article, we&#8217;ve explored how to create tabs in Next.js using the custom component and the styled-jsx library. We&#8217;ve also looked at how to handle the active state of the tabs and make the tabs look like they&#8217;re part of a traditional tabbed interface. Hope you like this!<\/p>\n","protected":false},"excerpt":{"rendered":"Do you want to create tabbing in Next.JS but don&#8217;t know how to do this? Here are the&hellip;\n","protected":false},"author":1,"featured_media":6934,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[62],"tags":[174,178,179,64],"class_list":{"0":"post-6916","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-react","8":"tag-174","9":"tag-coding","10":"tag-next-js","11":"tag-reactjs"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.ardorsys.com\/blog\/wp-json\/wp\/v2\/posts\/6916","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ardorsys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ardorsys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ardorsys.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ardorsys.com\/blog\/wp-json\/wp\/v2\/comments?post=6916"}],"version-history":[{"count":0,"href":"https:\/\/www.ardorsys.com\/blog\/wp-json\/wp\/v2\/posts\/6916\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ardorsys.com\/blog\/wp-json\/wp\/v2\/media\/6934"}],"wp:attachment":[{"href":"https:\/\/www.ardorsys.com\/blog\/wp-json\/wp\/v2\/media?parent=6916"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ardorsys.com\/blog\/wp-json\/wp\/v2\/categories?post=6916"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ardorsys.com\/blog\/wp-json\/wp\/v2\/tags?post=6916"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}