return type of render() should be VNode instead of void
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 ?
Element
Element | Element[]
https://github.com/Tencent/omi/blob/master/packages/omi/src/render.js#L32https://github.com/Tencent/omi/blob/master/packages/omi/src/vdom/diff.js#L22
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')
3ks5zfa03#
@dntzhang That's why I defined the return type as void : we did not use the return value of render
void
render
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
4条答案
按热度按时间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 beElement | 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
b5buobof2#
3ks5zfa03#
@dntzhang That's why I defined the return type as
void
: we did not use the return value ofrender
zf2sa74q4#
What if I want to use the return value of render?