You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current toReact adapter from #15 does not work as expected. It always returns a new component, and therefore always a new nanocomponent.
If you convert the adapter to use es6 classes, it will work as expected:
functiontoReact(Component,react){assert.equal(typeofComponent,'function','nanocomponent-adapters/react: component should be type function')assert.equal(typeofreact,'object','nanocomponent-adapters/react: react should be type object')classClxextendsreact.Component{constructor(){super()this.comp=newComponent()this.node=nullthis.setRef=this.setRef.bind(this)}componentDidMount(){if(!this.comp.element){varel=this.comp.render(this.props)this.node.appendChild(el)}}setRef(_node){this.node=_node}componentWillReceiveProps(props){if(this.comp.element)this.comp.render(props)}shouldComponentUpdate(){returnfalse}render(props){returnreact.createElement('div',{ref: this.setRef})}}returnClx}
Here's a little demo. If you increment both components, and then trigger a full app re-render, the prototype based component will remount and es6 based will remain:
If we're open to using es6 classes I can open a PR request, if not, I was getting a bit stumped by the prototypes so maybe someone can help take a look!
The text was updated successfully, but these errors were encountered:
The current
toReact
adapter from #15 does not work as expected. It always returns a new component, and therefore always a new nanocomponent.If you convert the adapter to use es6 classes, it will work as expected:
Here's a little demo. If you increment both components, and then trigger a full app re-render, the prototype based component will remount and es6 based will remain:
demo: https://preact-adapter-test.glitch.me
code: https://glitch.com/edit/#!/preact-adapter-test?path=public/client.js:1:1
If we're open to using es6 classes I can open a PR request, if not, I was getting a bit stumped by the prototypes so maybe someone can help take a look!
The text was updated successfully, but these errors were encountered: