fatihsolhan / v-onboarding

v-onboarding is a super-slim, fully-typed onboarding component for Vue 3
https://v-onboarding.fatihsolhan.com/
MIT License
164 stars 20 forks source link

fix: `toRefs()` expects a reactive object but received a plain one (warning) #80

Closed rozsazoltan closed 9 months ago

rozsazoltan commented 10 months ago

Problem

const state = inject(STATE_INJECT_KEY, {} as Ref<OnboardingState>)
const { step, isFirstStep, isLastStep, options, next, previous, exit: stateExit, finish } = toRefs(state.value)

[!WARNING] toRefs() expects a reactive object but received a plain one.

Solution

const state = inject(STATE_INJECT_KEY, {} as Ref<OnboardingState>)
const { step, isFirstStep, isLastStep, options, next, previous, exit: stateExit, finish } = state.value

The use of toRefs is unnecessary when we do not intend to transform a reactive object. The type of the state variable used in VOnboardingStep.vue is already of type ref(). I consider the per-variable transformation performed on it to be unnecessary; the variables can be declared without using toRefs() as I did in the modifications of this PR. This eliminates the warning message. The type of the state will always be ref(), so using toRefs() is not justified.

[!NOTE]

Converts a reactive object to a plain object where each property of the resulting object is a ref pointing to the corresponding property of the original object. Each individual ref is created using toRef().

Vue Docs - toRefs

netlify[bot] commented 10 months ago

Deploy Preview for eloquent-lamport-f2ffa1 canceled.

Name Link
Latest commit f60652f12eeaec6e873fa6bb9ccb1831477d9d76
Latest deploy log https://app.netlify.com/sites/eloquent-lamport-f2ffa1/deploys/64f309ad558810000828483f
netlify[bot] commented 10 months ago

Deploy Preview for beamish-dango-bc9c2d canceled.

Name Link
Latest commit f60652f12eeaec6e873fa6bb9ccb1831477d9d76
Latest deploy log https://app.netlify.com/sites/beamish-dango-bc9c2d/deploys/64f309ada84071000884c897
fatihsolhan commented 9 months ago

Thank you @rozsazoltan, I appreciate your support on v-onboarding πŸ’ͺ

github-actions[bot] commented 9 months ago

:tada: This PR is included in version 2.5.2 :tada:

The release is available on:

Your semantic-release bot :package::rocket: