1

Pretty much as title..

I declared my global styles.css inside _app.js as follow:

import '../public/styles.css'

then inside a page header.js (/components/header.js) i'm using a class .buttonPrimary present inside above mentioned global css file, as follow:

          <a
            href={`/api/auth/signin`}
            className={buttonPrimary}    // THIS
            onClick={(e) => {
              e.preventDefault()
              signIn()
            }}
          >
            Sign in
          </a>

but it throws error that the class doesn't exists.. I know I could do an import at the top of the page of the same global css file, but what would be the point of loading it globally inside _app.js then?

2 Answers 2

2

Try to just use the class as a string

 <a
  href={`/api/auth/signin`}
  className="buttonPrimary"
  onClick={(e) => {
    e.preventDefault()
    signIn()
  }}
>
  Sign in
</a>

Your bundler will connect the css file to the final bundle, and react will render. As a result we get html:

<a href="/api/auth/signin" class="buttonPrimary">Sign in</a>
Sign up to request clarification or add additional context in comments.

Comments

0

You need to pass the className as a string

<a
 href={`/api/auth/signin`}
 className="buttonPrimary"
 onClick={(e) => {
  e.preventDefault()
  signIn()
 }}
 >
 Sign in
</a>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.