What is Chakra UI?
Have you ever struggled with whether to focus more on the back-end or front-end of your project? Well believe me, both are equally important.
I started using Chakra UI because I wanted to focus on my back-end code more than being stuck on "How to center a div element?".
Chakra UI is extremely simple to use, especially when you are familiar with how to use ReactJs components.
How to Get Started and Install Chakra UI
Inside your respective directory, install ChakraUI using Yarn or NPM
yarn add @chakra-ui/react @emotion/react@^11 @emotion/styled@^11 framer-motion@^4
npm i @chakra-ui/react @emotion/react@^11 @emotion/styled@^11 framer-motion@^4
For React:
For ChakraUI to get initialised you first need to add <ChakraProvider>
in your index.js
file.
import React from "react"
// 1. import `ChakraProvider` component
import { ChakraProvider } from "@chakra-ui/react"
function App({ Component }) {
// 2. Use at the root of your app
return (
<ChakraProvider>
<Component />
</ChakraProvider>
)
}
For Next.js
Go to pages/_app.js
and add the following lines of code:
import { ChakraProvider } from "@chakra-ui/react"
function MyApp({ Component, pageProps }) {
return (
<ChakraProvider>
<Component {...pageProps} />
</ChakraProvider>
)
}
export default MyApp