From 2976aebfc139a64dd9703d6abbc830c00d1db6e7 Mon Sep 17 00:00:00 2001
From: Zeke Zhang <958414905@qq.com>
Date: Tue, 12 Nov 2024 08:12:54 +0800
Subject: [PATCH] perf(TemplateBlockProvider): use performance hooks
---
.../src/block-provider/TemplateBlockProvider.tsx | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/packages/core/client/src/block-provider/TemplateBlockProvider.tsx b/packages/core/client/src/block-provider/TemplateBlockProvider.tsx
index 71d530b2af..5d8c56aa4a 100644
--- a/packages/core/client/src/block-provider/TemplateBlockProvider.tsx
+++ b/packages/core/client/src/block-provider/TemplateBlockProvider.tsx
@@ -7,7 +7,7 @@
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
-import React, { createContext, useContext, useState } from 'react';
+import React, { createContext, useCallback, useContext, useMemo, useState } from 'react';
const TemplateBlockContext = createContext<{
// 模板是否已经请求结束
@@ -25,11 +25,9 @@ export const useTemplateBlockContext = () => {
const TemplateBlockProvider = (props) => {
const [templateFinished, setTemplateFinished] = useState(false);
- return (
- setTemplateFinished(true) }}>
- {props.children}
-
- );
+ const onTemplateSuccess = useCallback(() => setTemplateFinished(true), []);
+ const value = useMemo(() => ({ templateFinished, onTemplateSuccess }), [onTemplateSuccess, templateFinished]);
+ return {props.children};
};
export { TemplateBlockProvider };