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

epggiuax  于 2022-10-20  发布在  其他
关注(0)|答案(4)|浏览(214)

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

4c8rllxm

4c8rllxm1#

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

b5buobof

b5buobof2#

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')
3ks5zfa0

3ks5zfa03#

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

zf2sa74q

zf2sa74q4#

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

相关问题