preact-habitat icon indicating copy to clipboard operation
preact-habitat copied to clipboard

Feat: Should rerender component when called `render` again?

Open imcuttle opened this issue 7 years ago • 3 comments
trafficstars

The code rejected rerender from outside by calling render https://github.com/zouhir/preact-habitat/blob/69699493715f002ccf37ac85d5af342628b50a37/src/lib.js#L123-L125

const { render } = habitat(MyComponent)

render({
   selector: '.app',
})

// the blow renderer does not work
render({
  selector: '.app',
  defaultProps: { foo: 'bar' }
})

imcuttle avatar Nov 07 '18 02:11 imcuttle

I never had use case where this is useful, but, when a developer explicitly calls render() I think we should do it. I will have this in mind, thanks.

zouhir avatar Nov 14 '18 15:11 zouhir

I will add force option.

zouhir avatar Oct 24 '21 02:10 zouhir

This bug means that you cannot use preact-habitat on the same selector more than once

for example if someone is using this library for 2 widgets on their site (usually widgets will use the body selector), only the first one will work

Edit: turns out it doesn't matter anyway because preact renders a tree only once for each root container, i needed to do this:

// preact will render only once for each container
const container = document.createElement('div')
document.body.appendChild(container)
render(<App />, container)

remorses avatar Sep 27 '22 20:09 remorses