|
1 | 1 | import type { EffectScope, Ref, UnwrapNestedRefs, UnwrapRef } from '@vue/runtime-core' |
2 | 2 | // @ts-expect-error setCurrentInstance not exposed |
3 | | -import { createHook, effectScope, isProxy, isRef, nextTick, provide, reactive, readonly, setCurrentInstance, unref, watch } from '@vue/runtime-core' |
| 3 | +import { createHook, effectScope, isProxy, isRef, nextTick, provide, reactive, readonly, ref, setCurrentInstance, unref, watch } from '@vue/runtime-core' |
4 | 4 | import { Fragment, createElement, useEffect, useRef, useState } from 'react' |
5 | 5 |
|
6 | 6 | import type { ReactivueInternalInstance } from './shared' |
@@ -120,10 +120,17 @@ export function createSetup<PropsType, State>( |
120 | 120 | } |
121 | 121 | } |
122 | 122 | // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint |
123 | | -export const onPropsUpdated = <Props extends any>(fn: (newProps: Props) => void) => { |
| 123 | +export const onPropsUpdated = <Props extends Record<any, any>>(fn: (newProps: Props) => void) => { |
124 | 124 | createHook(LifecycleHooks.PROPS_UPDATED)(fn) |
125 | 125 | } |
126 | 126 |
|
| 127 | +// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-constraint |
| 128 | +export const useProps = <Props extends Record<any, any>>(props: Props) => { |
| 129 | + const reactiveProps = ref(props) |
| 130 | + onPropsUpdated<Props>(newProps => reactiveProps.value = newProps) |
| 131 | + return reactiveProps |
| 132 | +} |
| 133 | + |
127 | 134 | export function ReactivueProvider({ plugins, children }: { plugins?: any[]; children?: JSX.Element | JSX.Element[] }): JSX.Element { |
128 | 135 | const scope = useRef<EffectScope | null>(null) |
129 | 136 | if (scope.current === null) |
|
0 commit comments