Created
September 28, 2022 02:31
Next.js Emotion.js Setup Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @type {import('next').NextConfig} */ | |
const nextConfig = { | |
reactStrictMode: true, | |
swcMinify: true, | |
compiler: { | |
emotion: true, // IMPORTANT | |
}, | |
} | |
module.exports = nextConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { css } from "@emotion/react"; | |
import { NextPage } from "next"; | |
const ReactPage: NextPage = () => { | |
const color = 'white' | |
return ( | |
<div | |
css={css` | |
padding: 32px; | |
background-color: hotpink; | |
font-size: 24px; | |
border-radius: 4px; | |
&:hover { | |
color: ${color}; | |
} | |
`} | |
> | |
Hover to change color. | |
</div> | |
) | |
} | |
export default ReactPage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import styled from "@emotion/styled"; | |
import { NextPage } from "next"; | |
const StyledPage: NextPage = () => { | |
const Button = styled.button` | |
padding: 32px; | |
background-color: hotpink; | |
font-size: 24px; | |
border-radius: 4px; | |
color: black; | |
font-weight: bold; | |
&:hover { | |
color: white; | |
} | |
` | |
return <Button>This my button component.</Button> | |
} | |
export default StyledPage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"compilerOptions": { | |
"target": "es5", | |
"lib": ["dom", "dom.iterable", "esnext"], | |
"allowJs": true, | |
"skipLibCheck": true, | |
"strict": true, | |
"forceConsistentCasingInFileNames": true, | |
"noEmit": true, | |
"esModuleInterop": true, | |
"module": "esnext", | |
"moduleResolution": "node", | |
"resolveJsonModule": true, | |
"isolatedModules": true, | |
"jsx": "preserve", | |
"jsxImportSource": "@emotion/react", // IMPORTANT | |
"incremental": true | |
}, | |
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], | |
"exclude": ["node_modules"] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment