4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Chakra UI】import文が長くなりすぎる問題を何とかする方法

Last updated at Posted at 2024-08-05

はじめに

Chakra UIに初めて触れてみましたが、様々な部品が用意されて感動する反面、タイトルのような問題(?)が出てきたので対応する方法です。

問題

Chakura UIで用意されている、様々なコンポーネントを1つのファイル内で沢山importしているせいで、import文がやたら長くなるのがちょっとダサいなと思ったので、それを解決する方法です。

解決方法

ES Modulesのimport文にはアスタリスク(*)が使える。

例(対応前):

import {
  Box,
  Button,
  Input,
  Center,
  Flex,
  Img,
  Alert,
  Drawer,
  Stack,
  Divider,
  Card,
} from "@chakra-ui/react";

例(対応後):

import * as UI from "@chakra-ui/react";

使い方:

使用例
<UI.Button type="submit">登録</UI.Button>

おわりに

ググってもChakra UIを上記のように使う人は居なかったっぽいのでこういう使い方は普通しないのかもしれません…

JISOUのメンバー募集中🔥

プログラミングコーチングJISOUではメンバーを募集しています。
日本一のアウトプットコミュニティでキャリアアップしませんか?
気になる方はぜひHPからライン登録お願いします!👇

4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?