sparks-cyclejs icon indicating copy to clipboard operation
sparks-cyclejs copied to clipboard

React component unmount

Open wclr opened this issue 9 years ago • 5 comments

https://github.com/sdebaun/sparks-cyclejs/blob/release/src/helpers/dom/index.js#L11

I think just using hook is not enogth for correct component unmount. I mean that when element removed from DOM unmount lifecycle methods on React component will not be called automatically.

wclr avatar Mar 05 '16 22:03 wclr

@whitecolor Thank you for the issue. I think you are definitely correct here. I'm not very familiar with React myself. Do you believe something like:

export const reactComponent = (Klass, attrs, hookname = 'update') => 
  div({
    hook: {
      [hookname]: ({elm}) => ReactDOM.render(<Klass {...attrs} />, elm),
+     destroy: ({elm}) => ReactDOM.unmountComponentAtNode(elm)
    }
  })

Would be enough to ensure all of the React specfics are being handled?

TylorS avatar Mar 06 '16 18:03 TylorS

I think yes, it should work this way. Snabdom seems to have very good api for that, if it works fine for any kind of elements without perfomance penalty it is great.

virtual-dom has very poor API for hooks it actually has only init of snabbdom's.

is cycle-snabdom ready for prod?

wclr avatar Mar 06 '16 18:03 wclr

I would definitely say yes, it shares every single test that @cycle/dom does (minus one regarding virtual-dom widgets), and then some more that are specific to snabbdom.

TylorS avatar Mar 06 '16 19:03 TylorS

@whitecolor thank you for the suggestion! I'm wondering if it might be worth it to extract this into a simple snabbdom-react-component package?

sdebaun avatar Mar 06 '16 19:03 sdebaun

I think no reason to extract it to package yet, it probably doesn't cover all the use cases.

wclr avatar Mar 07 '16 10:03 wclr