editor data refactor - setEditorData can be called with function

This commit is contained in:
Jan Prochazka
2020-12-27 15:38:16 +01:00
parent ab0a551d67
commit 0747614e00
5 changed files with 207 additions and 121 deletions

View File

@@ -94,8 +94,12 @@ export default function useEditorData({ tabid, reloadToken = 0, loadFromArgs = n
const saveToStorageDebounced = React.useMemo(() => _.debounce(saveToStorage, 5000), [saveToStorage]);
const handleChange = (newValue) => {
if (newValue != null) valueRef.current = newValue;
setValue(newValue);
if (_.isFunction(newValue)) {
valueRef.current = newValue(valueRef.current);
} else {
if (newValue != null) valueRef.current = newValue;
}
setValue(valueRef.current);
changeCounterRef.current += 1;
saveToStorageDebounced();
};