Use scopeStore in useScopeValueSetterOnly (#16341)

GitOrigin-RevId: ed3c5937bafc984440ee262c8cb0c1ba63f0be7d
This commit is contained in:
Alf Eaton 2024-01-03 11:13:13 +00:00 committed by Copybot
parent eb3e5037f8
commit 12646d0541

View file

@ -19,7 +19,7 @@ export default function useScopeValueSetterOnly<T = any>(
path: string, // dot '.' path of a property in the Angular scope.
defaultValue?: T
): [T | undefined, Dispatch<SetStateAction<T | undefined>>] {
const { $scope } = useIdeContext()
const { scopeStore } = useIdeContext()
const [value, setValue] = useState<T | undefined>(defaultValue)
@ -27,11 +27,11 @@ export default function useScopeValueSetterOnly<T = any>(
(newValue: SetStateAction<T | undefined>) => {
setValue(val => {
const actualNewValue = _.isFunction(newValue) ? newValue(val) : newValue
$scope.$applyAsync(() => _.set($scope, path, actualNewValue))
scopeStore.set(path, actualNewValue)
return actualNewValue
})
},
[path, $scope]
[path, scopeStore]
)
return [value, scopeSetter]