update hook hellowlrld sample,
This commit is contained in:
26
002_source/cms/src/hooks/use-helloworld.ts
Normal file
26
002_source/cms/src/hooks/use-helloworld.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import * as React from 'react';
|
||||
|
||||
interface DialogController<T> {
|
||||
data?: T;
|
||||
handleClose: () => void;
|
||||
handleOpen: (data?: T) => void;
|
||||
open: boolean;
|
||||
}
|
||||
|
||||
export function useHelloworld<T = unknown>(): DialogController<T> {
|
||||
const [state, setState] = React.useState<{ open: boolean; data?: T }>({ open: false, data: undefined });
|
||||
|
||||
const handleOpen = React.useCallback((data?: T) => {
|
||||
setState({ open: true, data });
|
||||
}, []);
|
||||
|
||||
const handleClose = React.useCallback(() => {
|
||||
setState({ open: false });
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => {
|
||||
console.log('helloworld from useHelloworld');
|
||||
}, []);
|
||||
|
||||
return { data: state.data, handleClose, handleOpen, open: state.open };
|
||||
}
|
Reference in New Issue
Block a user