mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 23:46:02 +00:00
perf(TemplateBlockProvider): use performance hooks
This commit is contained in:
parent
87b67bc460
commit
2976aebfc1
@ -7,7 +7,7 @@
|
|||||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
* 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<{
|
const TemplateBlockContext = createContext<{
|
||||||
// 模板是否已经请求结束
|
// 模板是否已经请求结束
|
||||||
@ -25,11 +25,9 @@ export const useTemplateBlockContext = () => {
|
|||||||
|
|
||||||
const TemplateBlockProvider = (props) => {
|
const TemplateBlockProvider = (props) => {
|
||||||
const [templateFinished, setTemplateFinished] = useState(false);
|
const [templateFinished, setTemplateFinished] = useState(false);
|
||||||
return (
|
const onTemplateSuccess = useCallback(() => setTemplateFinished(true), []);
|
||||||
<TemplateBlockContext.Provider value={{ templateFinished, onTemplateSuccess: () => setTemplateFinished(true) }}>
|
const value = useMemo(() => ({ templateFinished, onTemplateSuccess }), [onTemplateSuccess, templateFinished]);
|
||||||
{props.children}
|
return <TemplateBlockContext.Provider value={value}>{props.children}</TemplateBlockContext.Provider>;
|
||||||
</TemplateBlockContext.Provider>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export { TemplateBlockProvider };
|
export { TemplateBlockProvider };
|
||||||
|
Loading…
Reference in New Issue
Block a user