Removed React prefix to some use hooks
This commit is contained in:
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user