Removed React prefix to some use hooks

This commit is contained in:
Donkie
2024-08-06 14:28:09 +02:00
parent 701ed2fae6
commit 3bd93cb0af
13 changed files with 53 additions and 71 deletions

View File

@@ -1,7 +1,7 @@
import { LiveEvent } from "@refinedev/core";
import React from "react";
import liveProvider from "./liveProvider";
import { getAPIURL } from "../utils/url";
import { useEffect, useMemo, useState } from "react";
const liveProviderInstance = liveProvider(getAPIURL());
@@ -18,22 +18,22 @@ export function useLiveify<Data extends { id: number }>(
) {
// TODO: The hooks in this function is quite janky, and should be refactored to be more efficient
// New state that holds the dataSource with updated values from the live provider
const [updatedDataSource, setUpdatedDataSource] = React.useState<Data[]>(dataSource);
const [updatedDataSource, setUpdatedDataSource] = useState<Data[]>(dataSource);
// If the original dataSource changes, update the updatedDataSource
React.useEffect(() => {
useEffect(() => {
setUpdatedDataSource(dataSource);
}, [dataSource]);
// Create a constant reference to itemIds. This is to prevent the useEffect below from triggering extra times.
const itemIds = dataSource.map((item) => item.id);
const [prevItemIds, setPrevItemIds] = React.useState<number[]>(itemIds);
const [prevItemIds, setPrevItemIds] = useState<number[]>(itemIds);
if (JSON.stringify(itemIds) !== JSON.stringify(prevItemIds)) {
setPrevItemIds(itemIds);
}
// Subscribe to changes for all items in the dataSource
React.useEffect(() => {
useEffect(() => {
const subscription = liveProviderInstance?.subscribe({
channel: `${resource}-list`,
params: {