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

return type of render() should be VNode instead of void #221

Open
rainmanhhh opened this issue Dec 17, 2018 · 4 comments
Open

return type of render() should be VNode instead of void #221

rainmanhhh opened this issue Dec 17, 2018 · 4 comments
Assignees

Comments

@rainmanhhh
Copy link

return type of render() should be VNode instead of void

@xcatliu xcatliu self-assigned this Dec 18, 2018
@xcatliu
Copy link
Collaborator

xcatliu commented Dec 18, 2018

According to the source code, the return type of render should be Element, But it also can be an array of Element, so it should be Element | Element[] right @dntzhang ?

https://github.com/Tencent/omi/blob/master/packages/omi/src/render.js#L32
https://github.com/Tencent/omi/blob/master/packages/omi/src/vdom/diff.js#L22

@dntzhang
Copy link
Collaborator

import { render, WeElement, define } from 'omi'

define('my-counter', class extends WeElement {
    static observe = true
    
    data = {
      count: 1
    }

    sub = () => {
      this.data.count--
    }

    add = () => {
      this.data.count++
    }

    render() {
     //here?  void? vnode?
      return  null
    }
  })

render(<my-counter />, 'body')
@xcatliu
Copy link
Collaborator

xcatliu commented Dec 18, 2018

@dntzhang That's why I defined the return type as void: we did not use the return value of render

@xcatliu
Copy link
Collaborator

xcatliu commented Dec 18, 2018

What if I want to use the return value of render?

let foo = render(<my-counter />, 'body');
console.log(foo);
// What type will foo be
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants