zouhir / preact-habitat

Zero configuration Preact widgets renderer in any host DOM
MIT License
518 stars 43 forks source link

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

Open imcuttle opened 5 years ago

imcuttle commented 5 years ago

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' }
})
zouhir commented 5 years ago

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 commented 2 years ago

I will add force option.

remorses commented 2 years ago

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)