Inferno: MobX Provider produces Error with hyperscript

Created on 17 Jan 2017  路  5Comments  路  Source: infernojs/inferno

Observed Behaviour

Inferno is producing an error when using Provider from inferno-mobx in hyperscript:

Inferno Error: a valid Inferno VNode (or null) must be returned from a component render. You may have returned an array or an invalid object.

The offending code snippet:

Inferno.render(
    h(Provider, {ls},[
        h('div', ls.map((l) => h(ConnectedComponent, {l})))
    ])

Full example:
```
import Inferno from 'inferno'
import { connect, Provider } from 'inferno-mobx'
import { observable } from 'mobx'
import h from 'inferno-hyperscript';

var ConnectedComponent = connect(['ls'], function({l}){
return h('div', [
h('p', l.title),
]);
});

const ls = observable([
observable({
language: 'english',
title: 'Hello World'
}),
observable({
language: 'french',
title: 'Bonjour tout le monde'
})
])

Inferno.render(
h(Provider, {ls},[
h('div', ls.map((l) => h(ConnectedComponent, {l})))
])
, document.getElementById('main'))
```

Expected Current Behaviour

Inferno should not produce an error.

Inferno Metadata

Linux/Chromium

Thank you!

bug to verify

Most helpful comment

@briansakal As doesn't render anything, it seemly returns its children from the render function. In this case, you're providing an array, and a component can't return an array. In this case, ensure the direct descendant of is singular.

Inferno.render(
  h(Provider, {ls},
    h('div', ls.map((l) => h(ConnectedComponent, {l})))
  ), document.getElementById('main'));

I'm hesitant at calling this an error since you'd get the same behavior from the createElement API.

All 5 comments

@briansakal As doesn't render anything, it seemly returns its children from the render function. In this case, you're providing an array, and a component can't return an array. In this case, ensure the direct descendant of is singular.

Inferno.render(
  h(Provider, {ls},
    h('div', ls.map((l) => h(ConnectedComponent, {l})))
  ), document.getElementById('main'));

I'm hesitant at calling this an error since you'd get the same behavior from the createElement API.

That makes perfect sense, I didn't know what Provider did internally. I treated it as any other Component because that's how I saw it used in JSX style, so I figured in hyperscript I should treat it like an other Component. Should I close the issue?

Good to hear you got it sorted out. Closing :)

Hi @Havunen, I get the same error as @briansakal when using JSX and following the example from the docs... https://infernojs.org/docs/api/inferno-mobx

Any ideas why?

Thanks

Urgh 馃檮 scrap that!! My mistake!

I added the connect function to the wrong component. It's too early in the morning 馃槀

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nassirdreffy picture nassirdreffy  路  4Comments

Vpr99 picture Vpr99  路  4Comments

Havunen picture Havunen  路  3Comments

oleksiibilous picture oleksiibilous  路  5Comments

xkxx picture xkxx  路  4Comments