2/n reduce react re-renders

This commit is contained in:
Igor Katson 2023-12-19 23:05:57 +00:00
parent e6ef3ff23f
commit 89bbcd2a27
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
7 changed files with 66 additions and 25 deletions

View file

@ -8,7 +8,9 @@ export const RootContent = (props: {}) => {
let setCloseableError = useErrorStore((state) => state.setCloseableError);
let otherError = useErrorStore((state) => state.otherError);
let torrents = useTorrentStore((state) => state.torrents);
let torrentsLoading = useTorrentStore((state) => state.torrentsLoading);
let torrentsInitiallyLoading = useTorrentStore(
(state) => state.torrentsInitiallyLoading
);
return (
<div className="container mx-auto">
@ -17,7 +19,7 @@ export const RootContent = (props: {}) => {
remove={() => setCloseableError(null)}
/>
<ErrorComponent error={otherError} />
<TorrentsList torrents={torrents} loading={torrentsLoading} />
<TorrentsList torrents={torrents} loading={torrentsInitiallyLoading} />
</div>
);
};

View file

@ -1,15 +1,13 @@
import { useCallback, useContext, useEffect, useState } from "react";
import { useContext, useEffect, useState } from "react";
import { AddTorrentResponse, AddTorrentOptions } from "../../api-types";
import { APIContext } from "../../context";
import { ErrorComponent } from "../ErrorComponent";
import { formatBytes } from "../../helper/formatBytes";
import { ErrorWithLabel } from "../../rqbit-web";
import { Spinner } from "../Spinner";
import { Modal } from "./Modal";
import { ModalBody } from "./ModalBody";
import { ModalFooter } from "./ModalFooter";
import { Button } from "../buttons/Button";
import { FormCheckbox } from "../forms/FormCheckbox";
import { Fieldset } from "../forms/Fieldset";
import { FormInput } from "../forms/FormInput";
import { Form } from "../forms/Form";
@ -40,7 +38,6 @@ export const FileSelectionModal = (props: {
const API = useContext(APIContext);
useEffect(() => {
console.log(listTorrentResponse);
setSelectedFiles(
new Set(listTorrentResponse?.details.files.map((_, i) => i))
);