Skip to content

[FeatureRequest] setup return render function #13

Open
@xialvjun

Description

@xialvjun

change

import { UnwrapRef } from '@vue/reactivity'
import { useSetup } from './useSetup'

export function defineComponent<PropsType, State>(
  setupFunction: (props: PropsType) => State,
  renderFunction: (state: UnwrapRef<State>) => JSX.Element,
): (props: PropsType) => JSX.Element {
  return (props: PropsType) => {
    const state = useSetup(setupFunction, props)
    return renderFunction(state)
  }
}

to

import { UnwrapRef } from '@vue/reactivity'
import { useSetup } from './useSetup'

export function defineComponent<PropsType, State>(
  setupFunction: (props: PropsType) => State | () => JSX.Element,
  renderFunction?: (state: UnwrapRef<State>) => JSX.Element,
): (props: PropsType) => JSX.Element {
  return (props: PropsType) => {
    const stateOrRender = useSetup(setupFunction, props)
    return renderFunction ?  renderFunction(stateOrRender) : stateOrRender();
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions