inferno icon indicating copy to clipboard operation
inferno copied to clipboard

[Request] Integrate inferno-mobx with Inferno's functional components

Open imetallica opened this issue 8 years ago • 5 comments

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.

imetallica avatar Feb 08 '17 13:02 imetallica

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")
)

imetallica avatar Feb 08 '17 15:02 imetallica

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

Havunen avatar Feb 22 '17 14:02 Havunen

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...

Havunen avatar Apr 15 '17 04:04 Havunen

Basically it means with the current state of mobx integration using functional components is anti pattern

Havunen avatar Apr 15 '17 04:04 Havunen

@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).

robbiespeed avatar Dec 07 '19 02:12 robbiespeed