inferno
inferno copied to clipboard
[Request] Integrate inferno-mobx with Inferno's functional components
Is it possible to create an API for functional components?
Currently, it only supports Component classes and stateless components. So it's quite awkward if we need to generate side-effects on initialization, for example.
This is the error I get when I try to use mobx
with functional components:
Error: Inferno Error: functional component lifecycle events are not supported on ES2015 class components
And this is my code:
const Survey = connect (['surveyStore'], function(props) {
return (
<div>
<Writer onComponentDidMount={ loadEditor } />
<a onClick={ linkEvent(props, addAnswer) }>Adicionar resposta</a>
{props.surveyStore.answers}
</div>
)
})
Inferno.render(
<Provider surveyStore={SurveyStore}>
<Survey
onComponentShouldUpdate={myUpdateFunction} />
</Provider>,
document.getElementById("app")
)
Currently focus is on fixing bugs and making 1.3 stable. This is something we could implement or at least investigate for Inferno 1.4
I did short investigation on this and it seems that mobx is wrapping all functional components with class components to be able to re-render them...
Basically it means with the current state of mobx integration using functional components is anti pattern
@Havunen I could take a look at fixing this, I'm going to be writing inferno integration for my own state management library which functions using a similar observer pattern to mobX. It wouldn't be hard to port whatever I do to mobX, my main concern is what Inferno APIs are considered stable, because doing this work would require forcing an update of a functional component which is only possible using undocumented internal functions (I think patch
).