Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FeatureRequest] setup return render function #13

Open
xialvjun opened this issue Jan 11, 2021 · 4 comments · May be fixed by #72
Open

[FeatureRequest] setup return render function #13

xialvjun opened this issue Jan 11, 2021 · 4 comments · May be fixed by #72

Comments

@xialvjun
Copy link

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();
  }
}
@xialvjun
Copy link
Author

sorry, seems this code is wrong.

@antfu
Copy link
Owner

antfu commented Jan 12, 2021

Cool, would you mind to draft a PR for it? Thanks!

@xialvjun
Copy link
Author

xialvjun commented Jan 12, 2021

I have read reactivue's code, it seems it's not that easy to change defineComponent to return a render function.

I've written some ideas to achieve this before, but it may be a big change. https://github.com/xialvjun/reactivity-react/blob/master/index.tsx

@antfu
Copy link
Owner

antfu commented Jan 12, 2021

I'd be appreciated if you can have a quick explanation of it. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants