0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Reactでローディングを実装する @yukilulu0229

Posted at

install

npm i react-loading-icons

使う

app.tsx
import { TailSpin } from "react-loading-icons";


const Chat = () => {
  const [isLoading, setIsLoading] = useState(false);
  
  const logic = async () => {
    setIsLoading(true);

    // なんかロジック中

    setIsLoading(false);
  };

  return (
    <div className="bg-gray-500 h-full p-4 flex flex-col">
      {isLoading && <TailSpin />}
    </div>
  );
};

export default Chat;

インポート

import { TailSpin } from "react-loading-icons";

コーディング

 {isLoading && <TailSpin />}

isLoadingがtrueなら表示

ロジック

const [isLoading, setIsLoading] = useState(false);

useStateで変更できるようにする

const logic = async () => {
    setIsLoading(true);

    // なんかロジック中

    setIsLoading(false);
};

ロジックの最中の処理

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?