Why you should use Chakra UI ⚡️ ?
Tags: chakraui, react, nextjs, css
Published: 2021-06-02 14:46:33

Before beginning coding one significant question sprung up always: _“Which library would it be a good idea to style the components?”_

I’ve worked on various libraries such as *Bootstrap, Material UI or styled-components*. And you may be thinking why you need another UI library when you already have a big alternative.
Recently, *Chakra UI ⚡️* has gained a lot of attraction because of its _accessibility_ and _high customization_.

### Installation⚙️

Chakra UI can be installed via NPM/Yarn.
 
```
// If you are using npm:
$ npm i @chakra-ui/react @emotion/react@^11 @emotion/styled@^11 framer-motion@^4

// or, using Yarn:
$ yarn add @chakra-ui/react @emotion/react@^11 @emotion/styled@^11 framer-motion@^4
```

Once the packages are installed, a provider needs to be configured.

```javascript 

import { ChakraProvider } from "@chakra-ui/react";

function MyApp({ Component, pageProps }) {
	return (
		<ChakraProvider>
			<Component {...pageProps} />
		</ChakraProvider>
	);
}

export default MyApp;
```

## Benefits of Chakra UI 📖

- *Simpler Components* : The best feature of Chakra UI is how components are designed to be small so that you can compose them together. You can build bigger elements easily by arranging them the same as HTML tags.

Let's look here: `Box` and `Text` are the most basic components just like `div` and `p` tags respectively. 

```javascript
<Header>
 <Box w={{ base: "70%", sm: "50%", md: "40%" }}>
   <Text>Hey, Adyasha!</Text>
   <Button>Click me</Button>
 </Box>
</Header>
```
Don't forgot to import the components: `Header`, `Box`, `Text` from _@chakra-ui/react_

> Note: For better sight, you can check the [official documentation](https://chakra-ui.com/docs/getting-started), there you can see plenty of components which will be enough for building your project.

- *Easy to theme and customize* : One of the advantages of Chakra UI is that you can easily adjust it to your design needs. Inside the styles folder, Create a _theme.js_ file. You can specify things like font-family, font-sizes, colors, breakpoints, etc.

```javascript
import { extendTheme } from '@chakra-ui/react'

const customtheme = extendTheme({
        Heading: {
            variants: {
                h1: {
                    fontSize: '4xl', fontWeight: 'bold'
                },
                h2: {
                    fontSize: '2xl', fontWeight: 'semibold'
                }
            }
        }
})

export default customtheme
```

- *Dark mode support* : By default, most of Chakra's components are dark mode compatible. A little bit of change in `theme config` and you are good to go ✈︎

![GIF](https://i.imgur.com/NnN3l2m.gif)

> Note: In some cases, when you switch to dark mode and refresh the page, you might experience a quick flash of white mode before it switches correctly and they're looking to fix it.

- *Responsive styles* : Chakra UI supports _responsive styles out of the box_. To add them, we can set default breakpoints or you can create your own.

```javascript
import { createBreakpoints } from "@chakra-ui/theme-tools"

const breakpoints = createBreakpoints({
  sm: "30em",
  md: "48em",
  lg: "62em",
  xl: "80em",
  "2xl": "96em",
})
```

You can use these breakpoints to resize your `box` or `div`:
```javascript
<Box width={{sm: '200px', md: '400px', xl: '600px'}}>
  Me, fully responsive :)
</Box>
```
### Preview 👀:

I built a simple project or you can say just a [landing page](https://chakra-ui-next-js.vercel.app/) with *NextJS* and *Chakra UI* and the reason behind this project is to learn more about the features of Chakra UI and it was by far the easiest component library I’ve tried so far.

Take a sneak peek:
![image](https://user-images.githubusercontent.com/54095539/120494197-3cc82000-c3d9-11eb-90ee-06625da641db.png)

> This is all only a little model I think if you want to cover all the customisation of this library go check the [official documentation](https://chakra-ui.com/docs/getting-started).

## 📍 Conclusion:

As a promising new library, it is constantly improving and the hype is building around the library. More components will probably be added soon. So you can consider using it for your next React project :D

I share what I think on [Twitter](https://twitter.com/Adyasha8105)💙. This post is also posted on my [blog](https://www.adyablogs.tech/blogs/Why-you-should-use-Chakra-UI-!) page.

## 🙌 Support me:

My projects are fueled by coffees ☕, get one for me!

<a href="https://www.buymeacoffee.com/Adyasha8105">
 <img width="100" src="https://res.cloudinary.com/practicaldev/image/fetch/s--8vsiOGpo--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/appcraftstudio/buymeacoffee/raw/master/Images/snapshot-bmc-button.png" class="loaded">
</a>