1
0
mirror of https://github.com/sasjs/server.git synced 2025-12-10 19:34:34 +00:00

Compare commits

...

15 Commits

Author SHA1 Message Date
semantic-release-bot
a531de2adb chore(release): 0.13.0 [skip ci]
# [0.13.0](https://github.com/sasjs/server/compare/v0.12.1...v0.13.0) (2022-07-28)

### Bug Fixes

* autofocus input field and submit on enter ([7681722](7681722e5a))
* move api button to user menu ([8de032b](8de032b543))

### Features

* add action and command to editor ([706e228](706e228a8e))
2022-07-28 19:27:12 +00:00
Allan Bowe
c458d94493 Merge pull request #239 from sasjs/issue-238
fix: improve user experience in the studio
2022-07-28 20:21:48 +01:00
706e228a8e feat: add action and command to editor 2022-07-28 23:56:44 +05:00
7681722e5a fix: autofocus input field and submit on enter 2022-07-28 23:55:59 +05:00
8de032b543 fix: move api button to user menu 2022-07-28 23:54:40 +05:00
semantic-release-bot
998ef213e9 chore(release): 0.12.1 [skip ci]
## [0.12.1](https://github.com/sasjs/server/compare/v0.12.0...v0.12.1) (2022-07-26)

### Bug Fixes

* **web:** disable launch icon button when file content is not saved ([c574b42](c574b42235))
* **web:** saveAs functionality fixed in studio page ([3c987c6](3c987c61dd))
* **web:** show original name as default name in rename file/folder modal ([9640f65](9640f65264))
* **web:** webout tab item fixed in studio page ([7cdffe3](7cdffe30e3))
* **web:** when no file is selected save the editor content to local storage ([3b1fcb9](3b1fcb937d))
2022-07-26 20:52:05 +00:00
Allan Bowe
f8b0f98678 Merge pull request #236 from sasjs/fix-studio
fix: issues fixed in studio page
2022-07-26 21:48:20 +01:00
9640f65264 fix(web): show original name as default name in rename file/folder modal 2022-07-27 01:44:13 +05:00
c574b42235 fix(web): disable launch icon button when file content is not saved 2022-07-27 01:42:46 +05:00
468d1a929d chore(web): quick fixes 2022-07-27 00:47:38 +05:00
7cdffe30e3 fix(web): webout tab item fixed in studio page 2022-07-26 23:53:07 +05:00
3b1fcb937d fix(web): when no file is selected save the editor content to local storage 2022-07-26 23:30:41 +05:00
3c987c61dd fix(web): saveAs functionality fixed in studio page 2022-07-26 23:15:42 +05:00
0a780697da chore(web): move hooks to hooks folder 2022-07-26 23:14:29 +05:00
83d819df53 chore(web): created custom useStateWithCallback hook 2022-07-26 23:12:55 +05:00
9 changed files with 241 additions and 73 deletions

View File

@@ -1,3 +1,27 @@
# [0.13.0](https://github.com/sasjs/server/compare/v0.12.1...v0.13.0) (2022-07-28)
### Bug Fixes
* autofocus input field and submit on enter ([7681722](https://github.com/sasjs/server/commit/7681722e5afdc2df0c9eed201b05add3beda92a7))
* move api button to user menu ([8de032b](https://github.com/sasjs/server/commit/8de032b5431b47daabcf783c47ff078bf817247d))
### Features
* add action and command to editor ([706e228](https://github.com/sasjs/server/commit/706e228a8e1924786fd9dc97de387974eda504b1))
## [0.12.1](https://github.com/sasjs/server/compare/v0.12.0...v0.12.1) (2022-07-26)
### Bug Fixes
* **web:** disable launch icon button when file content is not saved ([c574b42](https://github.com/sasjs/server/commit/c574b4223591c4a6cd3ef5e146ce99cd8f7c9190))
* **web:** saveAs functionality fixed in studio page ([3c987c6](https://github.com/sasjs/server/commit/3c987c61ddc258f991e2bf38c1f16a0c4248d6ae))
* **web:** show original name as default name in rename file/folder modal ([9640f65](https://github.com/sasjs/server/commit/9640f6526496f3564664ccb1f834d0f659dcad4e))
* **web:** webout tab item fixed in studio page ([7cdffe3](https://github.com/sasjs/server/commit/7cdffe30e36e5cad0284f48ea97925958e12704c))
* **web:** when no file is selected save the editor content to local storage ([3b1fcb9](https://github.com/sasjs/server/commit/3b1fcb937d06d02ab99c9e8dbe307012d48a7a3a))
# [0.12.0](https://github.com/sasjs/server/compare/v0.11.5...v0.12.0) (2022-07-26) # [0.12.0](https://github.com/sasjs/server/compare/v0.11.5...v0.12.0) (2022-07-26)

View File

@@ -22,8 +22,14 @@ const FilePathInputModal = ({
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const value = event.target.value const value = event.target.value
const regex = /\.(exe|sh|htaccess)$/i
if (regex.test(value)) { const specialChars = /[`!@#$%^&*()_+\-=[\]{};':"\\|,<>?~]/
const fileExtension = /\.(exe|sh|htaccess)$/i
if (specialChars.test(value)) {
setHasError(true)
setErrorText('can not have special characters')
} else if (fileExtension.test(value)) {
setHasError(true) setHasError(true)
setErrorText('can not save file with extensions [exe, sh, htaccess]') setErrorText('can not save file with extensions [exe, sh, htaccess]')
} else { } else {
@@ -33,21 +39,30 @@ const FilePathInputModal = ({
setFilePath(value) setFilePath(value)
} }
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault()
if (hasError || !filePath) return
saveFile(filePath)
}
return ( return (
<BootstrapDialog fullWidth onClose={() => setOpen(false)} open={open}> <BootstrapDialog fullWidth onClose={() => setOpen(false)} open={open}>
<BootstrapDialogTitle id="abort-modal" handleOpen={setOpen}> <BootstrapDialogTitle id="abort-modal" handleOpen={setOpen}>
Save File Save File
</BootstrapDialogTitle> </BootstrapDialogTitle>
<DialogContent dividers> <DialogContent dividers>
<TextField <form onSubmit={handleSubmit}>
fullWidth <TextField
variant="outlined" fullWidth
label="File Path" autoFocus
value={filePath} variant="outlined"
onChange={handleChange} label="File Path"
error={hasError} value={filePath}
helperText={errorText} onChange={handleChange}
/> error={hasError}
helperText={errorText}
/>
</form>
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
<Button variant="contained" onClick={() => setOpen(false)}> <Button variant="contained" onClick={() => setOpen(false)}>
@@ -55,9 +70,7 @@ const FilePathInputModal = ({
</Button> </Button>
<Button <Button
variant="contained" variant="contained"
onClick={() => { onClick={() => saveFile(filePath)}
saveFile(filePath)
}}
disabled={hasError || !filePath} disabled={hasError || !filePath}
> >
Save Save

View File

@@ -90,17 +90,6 @@ const Header = (props: any) => {
component={Link} component={Link}
/> />
</Tabs> </Tabs>
<Button
href={`${baseUrl}/SASjsApi`}
target="_blank"
rel="noreferrer"
variant="contained"
color="primary"
size="large"
endIcon={<OpenInNewIcon />}
>
API Docs
</Button>
<Button <Button
href={`${baseUrl}/AppStream`} href={`${baseUrl}/AppStream`}
target="_blank" target="_blank"
@@ -110,7 +99,7 @@ const Header = (props: any) => {
size="large" size="large"
endIcon={<OpenInNewIcon />} endIcon={<OpenInNewIcon />}
> >
App Stream Apps
</Button> </Button>
<div <div
style={{ style={{
@@ -138,18 +127,6 @@ const Header = (props: any) => {
open={!!anchorEl} open={!!anchorEl}
onClose={handleClose} onClose={handleClose}
> >
<MenuItem sx={{ justifyContent: 'center' }}>
<Button
href={'https://server.sasjs.io'}
target="_blank"
rel="noreferrer"
variant="contained"
color="primary"
size="large"
>
Documentation
</Button>
</MenuItem>
<MenuItem sx={{ justifyContent: 'center' }}> <MenuItem sx={{ justifyContent: 'center' }}>
<Button <Button
component={Link} component={Link}
@@ -162,6 +139,32 @@ const Header = (props: any) => {
Settings Settings
</Button> </Button>
</MenuItem> </MenuItem>
<MenuItem sx={{ justifyContent: 'center' }}>
<Button
href={'https://server.sasjs.io'}
target="_blank"
rel="noreferrer"
variant="contained"
size="large"
color="primary"
endIcon={<OpenInNewIcon />}
>
Docs
</Button>
</MenuItem>
<MenuItem sx={{ justifyContent: 'center' }}>
<Button
href={`${baseUrl}/SASjsApi`}
target="_blank"
rel="noreferrer"
variant="contained"
color="primary"
size="large"
endIcon={<OpenInNewIcon />}
>
API
</Button>
</MenuItem>
<MenuItem onClick={handleLogout} sx={{ justifyContent: 'center' }}> <MenuItem onClick={handleLogout} sx={{ justifyContent: 'center' }}>
<Button variant="contained" color="primary"> <Button variant="contained" color="primary">
Logout Logout

View File

@@ -1,4 +1,4 @@
import React, { useState } from 'react' import React, { useState, useEffect } from 'react'
import { Button, DialogActions, DialogContent, TextField } from '@mui/material' import { Button, DialogActions, DialogContent, TextField } from '@mui/material'
@@ -12,6 +12,7 @@ type NameInputModalProps = {
isFolder: boolean isFolder: boolean
actionLabel: string actionLabel: string
action: (name: string) => void action: (name: string) => void
defaultName?: string
} }
const NameInputModal = ({ const NameInputModal = ({
@@ -20,12 +21,25 @@ const NameInputModal = ({
title, title,
isFolder, isFolder,
actionLabel, actionLabel,
action action,
defaultName
}: NameInputModalProps) => { }: NameInputModalProps) => {
const [name, setName] = useState('') const [name, setName] = useState('')
const [hasError, setHasError] = useState(false) const [hasError, setHasError] = useState(false)
const [errorText, setErrorText] = useState('') const [errorText, setErrorText] = useState('')
useEffect(() => {
if (defaultName) setName(defaultName)
}, [defaultName])
const handleFocus = (
event: React.FocusEvent<HTMLInputElement | HTMLTextAreaElement, Element>
) => {
if (defaultName) {
event.target.select()
}
}
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => { const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const value = event.target.value const value = event.target.value
@@ -49,21 +63,32 @@ const NameInputModal = ({
setName(value) setName(value)
} }
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault()
if (hasError || !name) return
action(name)
}
return ( return (
<BootstrapDialog fullWidth onClose={() => setOpen(false)} open={open}> <BootstrapDialog fullWidth onClose={() => setOpen(false)} open={open}>
<BootstrapDialogTitle id="abort-modal" handleOpen={setOpen}> <BootstrapDialogTitle id="abort-modal" handleOpen={setOpen}>
{title} {title}
</BootstrapDialogTitle> </BootstrapDialogTitle>
<DialogContent dividers> <DialogContent dividers>
<TextField <form onSubmit={handleSubmit}>
fullWidth <TextField
variant="outlined" id="input-box"
label={isFolder ? 'Folder Name' : 'File Name'} fullWidth
value={name} autoFocus
onChange={handleChange} onFocus={handleFocus}
error={hasError} variant="outlined"
helperText={errorText} label={isFolder ? 'Folder Name' : 'File Name'}
/> value={name}
onChange={handleChange}
error={hasError}
helperText={errorText}
/>
</form>
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
<Button variant="contained" onClick={() => setOpen(false)}> <Button variant="contained" onClick={() => setOpen(false)}>
@@ -71,9 +96,7 @@ const NameInputModal = ({
</Button> </Button>
<Button <Button
variant="contained" variant="contained"
onClick={() => { onClick={() => action(name)}
action(name)
}}
disabled={hasError || !name} disabled={hasError || !name}
> >
{actionLabel} {actionLabel}

View File

@@ -67,6 +67,7 @@ const TreeViewNode = ({
useState(false) useState(false)
const [deleteConfirmationModalMessage, setDeleteConfirmationModalMessage] = const [deleteConfirmationModalMessage, setDeleteConfirmationModalMessage] =
useState('') useState('')
const [defaultInputModalName, setDefaultInputModalName] = useState('')
const [nameInputModalOpen, setNameInputModalOpen] = useState(false) const [nameInputModalOpen, setNameInputModalOpen] = useState(false)
const [nameInputModalTitle, setNameInputModalTitle] = useState('') const [nameInputModalTitle, setNameInputModalTitle] = useState('')
const [nameInputModalActionLabel, setNameInputModalActionLabel] = useState('') const [nameInputModalActionLabel, setNameInputModalActionLabel] = useState('')
@@ -129,6 +130,7 @@ const TreeViewNode = ({
setNameInputModalTitle('Add Folder') setNameInputModalTitle('Add Folder')
setNameInputModalActionLabel('Add') setNameInputModalActionLabel('Add')
setNameInputModalForFolder(true) setNameInputModalForFolder(true)
setDefaultInputModalName('')
} }
const handleNewFileItemClick = () => { const handleNewFileItemClick = () => {
@@ -137,6 +139,7 @@ const TreeViewNode = ({
setNameInputModalTitle('Add File') setNameInputModalTitle('Add File')
setNameInputModalActionLabel('Add') setNameInputModalActionLabel('Add')
setNameInputModalForFolder(false) setNameInputModalForFolder(false)
setDefaultInputModalName('')
} }
const addFileFolder = (name: string) => { const addFileFolder = (name: string) => {
@@ -152,6 +155,7 @@ const TreeViewNode = ({
setNameInputModalTitle('Rename') setNameInputModalTitle('Rename')
setNameInputModalActionLabel('Rename') setNameInputModalActionLabel('Rename')
setNameInputModalForFolder(node.isFolder) setNameInputModalForFolder(node.isFolder)
setDefaultInputModalName(node.relativePath.split('/').pop() ?? '')
} }
const renameFileFolder = (name: string) => { const renameFileFolder = (name: string) => {
@@ -208,6 +212,7 @@ const TreeViewNode = ({
action={ action={
nameInputModalActionLabel === 'Add' ? addFileFolder : renameFileFolder nameInputModalActionLabel === 'Add' ? addFileFolder : renameFileFolder
} }
defaultName={defaultInputModalName}
/> />
<Menu <Menu
open={contextMenu !== null} open={contextMenu !== null}

View File

@@ -14,7 +14,8 @@ import {
Select, Select,
SelectChangeEvent, SelectChangeEvent,
Tab, Tab,
Tooltip Tooltip,
Typography
} from '@mui/material' } from '@mui/material'
import { styled } from '@mui/material/styles' import { styled } from '@mui/material/styles'
@@ -29,7 +30,8 @@ import {
import Editor, { import Editor, {
MonacoDiffEditor, MonacoDiffEditor,
DiffEditorDidMount, DiffEditorDidMount,
EditorDidMount EditorDidMount,
monaco
} from 'react-monaco-editor' } from 'react-monaco-editor'
import { TabContext, TabList, TabPanel } from '@mui/lab' import { TabContext, TabList, TabPanel } from '@mui/lab'
@@ -39,7 +41,7 @@ import FilePathInputModal from '../../components/filePathInputModal'
import BootstrapSnackbar, { AlertSeverityType } from '../../components/snackbar' import BootstrapSnackbar, { AlertSeverityType } from '../../components/snackbar'
import Modal from '../../components/modal' import Modal from '../../components/modal'
import usePrompt from '../../utils/usePrompt' import { usePrompt, useStateWithCallback } from '../../utils/hooks'
const StyledTabPanel = styled(TabPanel)(() => ({ const StyledTabPanel = styled(TabPanel)(() => ({
padding: '10px' padding: '10px'
@@ -74,7 +76,7 @@ const SASjsEditor = ({
const [snackbarSeverity, setSnackbarSeverity] = useState<AlertSeverityType>( const [snackbarSeverity, setSnackbarSeverity] = useState<AlertSeverityType>(
AlertSeverityType.Success AlertSeverityType.Success
) )
const [prevFileContent, setPrevFileContent] = useState('') const [prevFileContent, setPrevFileContent] = useStateWithCallback('')
const [fileContent, setFileContent] = useState('') const [fileContent, setFileContent] = useState('')
const [log, setLog] = useState('') const [log, setLog] = useState('')
const [ctrlPressed, setCtrlPressed] = useState(false) const [ctrlPressed, setCtrlPressed] = useState(false)
@@ -88,21 +90,41 @@ const SASjsEditor = ({
const editorRef = useRef(null as any) const editorRef = useRef(null as any)
const diffEditorRef = useRef(null as any)
const handleEditorDidMount: EditorDidMount = (editor) => { const handleEditorDidMount: EditorDidMount = (editor) => {
editor.focus()
editorRef.current = editor editorRef.current = editor
editor.focus()
editor.addAction({
// An unique identifier of the contributed action.
id: 'show-difference',
// A label of the action that will be presented to the user.
label: 'Show Differences',
// An optional array of keybindings for the action.
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyD],
contextMenuGroupId: 'navigation',
contextMenuOrder: 1,
// Method that will be executed when the action is triggered.
// @param editor The editor instance is passed in as a convenience
run: function (ed) {
setShowDiff(true)
}
})
} }
const handleDiffEditorDidMount: DiffEditorDidMount = (diffEditor) => { const handleDiffEditorDidMount: DiffEditorDidMount = (diffEditor) => {
diffEditor.focus() diffEditor.focus()
diffEditorRef.current = diffEditor diffEditor.addCommand(monaco.KeyCode.Escape, function () {
setShowDiff(false)
})
} }
usePrompt( usePrompt(
'Changes you made may not be saved.', 'Changes you made may not be saved.',
prevFileContent !== fileContent prevFileContent !== fileContent && !!selectedFilePath
) )
useEffect(() => { useEffect(() => {
@@ -134,10 +156,21 @@ const SASjsEditor = ({
}) })
.finally(() => setIsLoading(false)) .finally(() => setIsLoading(false))
} else { } else {
setFileContent('') const content = localStorage.getItem('fileContent') ?? ''
setFileContent(content)
} }
setLog('')
setWebout('')
setTab('1')
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedFilePath]) }, [selectedFilePath])
useEffect(() => {
if (fileContent.length && !selectedFilePath) {
localStorage.setItem('fileContent', fileContent)
}
}, [fileContent, selectedFilePath])
useEffect(() => { useEffect(() => {
if (runTimes.includes(selectedFileExtension)) if (runTimes.includes(selectedFileExtension))
setSelectedRunTime(selectedFileExtension) setSelectedRunTime(selectedFileExtension)
@@ -211,6 +244,10 @@ const SASjsEditor = ({
const saveFile = (filePath?: string) => { const saveFile = (filePath?: string) => {
setIsLoading(true) setIsLoading(true)
if (filePath) {
filePath = filePath.startsWith('/') ? filePath : `/${filePath}`
}
const formData = new FormData() const formData = new FormData()
const stringBlob = new Blob([fileContent], { type: 'text/plain' }) const stringBlob = new Blob([fileContent], { type: 'text/plain' })
@@ -223,10 +260,22 @@ const SASjsEditor = ({
axiosPromise axiosPromise
.then(() => { .then(() => {
if (filePath) { if (filePath && fileContent === prevFileContent) {
// when fileContent and prevFileContent is same,
// callback function in setPrevFileContent method is not called
// because behind the scene useEffect hook is being used
// for calling callback function, and it's only fired when the
// new value is not equal to old value.
// So, we'll have to explicitly update the selected file path
setSelectedFilePath(filePath, true) setSelectedFilePath(filePath, true)
} else {
setPrevFileContent(fileContent, () => {
if (filePath) {
setSelectedFilePath(filePath, true)
}
})
} }
setPrevFileContent(fileContent)
setSnackbarMessage('File saved!') setSnackbarMessage('File saved!')
setSnackbarSeverity(AlertSeverityType.Success) setSnackbarSeverity(AlertSeverityType.Success)
setOpenSnackbar(true) setOpenSnackbar(true)
@@ -312,9 +361,14 @@ const SASjsEditor = ({
<TabList onChange={handleTabChange} centered> <TabList onChange={handleTabChange} centered>
<StyledTab label="Code" value="1" /> <StyledTab label="Code" value="1" />
<StyledTab label="Log" value="2" /> <StyledTab label="Log" value="2" />
<Tooltip title="Displays content from the _webout fileref"> <StyledTab
<StyledTab label="Webout" value="3" /> label={
</Tooltip> <Tooltip title="Displays content from the _webout fileref">
<Typography>Webout</Typography>
</Tooltip>
}
value="3"
/>
</TabList> </TabList>
</Box> </Box>
@@ -324,6 +378,8 @@ const SASjsEditor = ({
> >
<Box sx={{ display: 'flex', justifyContent: 'center' }}> <Box sx={{ display: 'flex', justifyContent: 'center' }}>
<RunMenu <RunMenu
fileContent={fileContent}
prevFileContent={prevFileContent}
selectedFilePath={selectedFilePath} selectedFilePath={selectedFilePath}
selectedRunTime={selectedRunTime} selectedRunTime={selectedRunTime}
runTimes={runTimes} runTimes={runTimes}
@@ -423,6 +479,8 @@ export default SASjsEditor
type RunMenuProps = { type RunMenuProps = {
selectedFilePath: string selectedFilePath: string
fileContent: string
prevFileContent: string
selectedRunTime: string selectedRunTime: string
runTimes: string[] runTimes: string[]
handleChangeRunTime: (event: SelectChangeEvent) => void handleChangeRunTime: (event: SelectChangeEvent) => void
@@ -431,6 +489,8 @@ type RunMenuProps = {
const RunMenu = ({ const RunMenu = ({
selectedFilePath, selectedFilePath,
fileContent,
prevFileContent,
selectedRunTime, selectedRunTime,
runTimes, runTimes,
handleChangeRunTime, handleChangeRunTime,
@@ -463,10 +523,21 @@ const RunMenu = ({
</Tooltip> </Tooltip>
{selectedFilePath ? ( {selectedFilePath ? (
<Box sx={{ marginLeft: '10px' }}> <Box sx={{ marginLeft: '10px' }}>
<Tooltip title="Launch program in new window"> <Tooltip
<IconButton onClick={launchProgram}> title={
<RocketLaunch /> fileContent !== prevFileContent
</IconButton> ? 'Save file before launching program'
: 'Launch program in new window'
}
>
<span>
<IconButton
disabled={fileContent !== prevFileContent}
onClick={launchProgram}
>
<RocketLaunch />
</IconButton>
</span>
</Tooltip> </Tooltip>
</Box> </Box>
) : ( ) : (

View File

@@ -0,0 +1,2 @@
export * from './usePrompt'
export * from './useStateWithCallback'

View File

@@ -2,7 +2,7 @@ import { useEffect, useCallback, useContext } from 'react'
import { UNSAFE_NavigationContext as NavigationContext } from 'react-router-dom' import { UNSAFE_NavigationContext as NavigationContext } from 'react-router-dom'
import { History, Blocker, Transition } from 'history' import { History, Blocker, Transition } from 'history'
function useBlocker(blocker: Blocker, when = true) { const useBlocker = (blocker: Blocker, when = true) => {
const navigator = useContext(NavigationContext).navigator as History const navigator = useContext(NavigationContext).navigator as History
useEffect(() => { useEffect(() => {
@@ -24,7 +24,7 @@ function useBlocker(blocker: Blocker, when = true) {
}, [navigator, blocker, when]) }, [navigator, blocker, when])
} }
export default function usePrompt(message: string, when = true) { export const usePrompt = (message: string, when = true) => {
const blocker = useCallback( const blocker = useCallback(
(tx) => { (tx) => {
if (window.confirm(message)) tx.retry() if (window.confirm(message)) tx.retry()

View File

@@ -0,0 +1,27 @@
import { useState, useEffect, useRef } from 'react'
export const useStateWithCallback = <T>(
initialValue: T
): [T, (newValue: T, callback?: () => void) => void] => {
const callbackRef = useRef<any>(null)
const [value, setValue] = useState(initialValue)
useEffect(() => {
if (typeof callbackRef.current === 'function') {
callbackRef.current()
callbackRef.current = null
}
}, [value])
const setValueWithCallback = (newValue: T, callback?: () => void) => {
callbackRef.current = callback
setValue(newValue)
}
return [value, setValueWithCallback]
}
export default useStateWithCallback