windows 10 pro office 2019 pro office 365 pro windows 10 home windows 10 enterprise office 2019 home and business office 2016 pro windows 10 education visio 2019 microsoft project 2019 microsoft project 2016 visio professional 2016 windows server 2012 windows server 2016 windows server 2019 Betriebssysteme office software windows server instagram takipçi instagram beğeni instagram görüntüleme instagram otomatik beğeni facebook beğeni facebook sayfa beğenisi facebook takipçi twitter takipçi twitter beğeni twitter retweet youtube izlenme youtube abone instagram

How do I use the npm classnames library in next.js to optionally apply styles from a css file?

Asked By: Anonymous

In the html below, I am optionally applying the bootstrap classes, alert-danger or alert-primary depending on message.error or The target classes are bootstrap classes and it works as expected.

   className={classnames(`alert, ${styles.alertDiv}`, {
   "alert-danger": message.error,

Now, in place of alert-danger, I want to apply a style from a css file, $(styles.activeDiv) if message.error is true. In other words I want to replace alert-danger with $(styles.activeDiv). How do I do this.


Answered By: Anonymous

In Next.js and in Bootstrap you are able to override the default CSS styling or write specific component level styling Next.js Built-in CSS Support. There are many ways to accomplish this, you could pass in a style object as an inline style attribute. I think a simple way to do it is just to useState hooks. This one toggles between two different CSS classes but you can alter to suit your needs:

In this example, the className changes when you click the div

codesandbox example of Dynamic ClassName

import { useState } from "react";

export default function IndexPage() {
  const [dynamicClassName, setDynamicClassName] = useState("info");
  const handleClassChange = () => {
    console.log("changing div class name");
    dynamicClassName === "info"
      ? setDynamicClassName("alert")
      : setDynamicClassName("info");

  return (
      <div className={dynamicClassName} onClick={handleClassChange}>
        This div has a dynamic CSS class based on click

      <style jsx>
          .alert {
            color: red;
            border: 5px solid red;

          .info {
            color: green;
            border: 5px solid green;

note: edited for a more specific working example

techinplanet staff

Windows 10 Kaufen Windows 10 Pro Office 2019 Kaufen Office 365 Lizenz Windows 10 Home Lizenz Office 2019 Home Business Kaufen windows office 365 satın al follower kaufen instagram follower kaufen porno
Alanya escort Manavgat escort Fethiye escort Kemer escort Didim escort Gaziantep escort Denizli escort Adana escort Hatay escort Aydın escort İzmir escort Ankara escort Antalya escort Bursa escort İstanbul escort Kocaeli escort Konya escort Muğla escort Malatya escort Kayseri escort Mersin escort Samsun escort Sinop escort Tekirdağ escort Eskişehir escort Yalova escort Rize escort Amasya escort Balıkesir escort Çanakkale escort Bolu escort Erzincan escort Şırnak escort Van escort Yozgat escort Zonguldak escort Afyon escort Adıyaman escort Bilecik escort Aksaray escort Ağri escort Bitlis escort Siirt escort Çorum escort Burdur escort Diyarbakir escort Edirne escort Düzce escort Erzurum escort Kırklareli escort Giresun escort Kilis escort Kars escort Karabük escort Kırıkkale escort Mardin escort Kırşehir escort Maraş escort Manisa escort Muş escort Kastamonu escort Ordu escort Nevşehir escort Sakarya escort Osmaniye escort Şanliurfa escort Sivas escort Trabzon escort Tokat escort Ardahan escort Bartın escort Karaman escort Batman escort Bayburt escort Bingöl escort Elaziğ escort Gümüşhane escort Hakkari escort Isparta escort Uşak escort Igdır escort