webpacker-react icon indicating copy to clipboard operation
webpacker-react copied to clipboard

Mount an Individual View Component

Open sealocal opened this issue 7 years ago • 2 comments

Is it possible to mount an individual component? If not, would it be a reasonable feature request?

My current approach is to unmount all components on the page and then mount them again - but, this resets the state of all components on the page - and I even get inconsistent results when I expect all components to reset.

Consider adding an instance of an Item component to a page through an ajax request:

document.getElementById('items')
  .insertAdjacentHTML('beforeend', '<%= j render partial: 'items/item', locals: { item: @item } %>');

WebpackerReact.unmountComponents()
WebpackerReact.mountComponents()

Here's a change to the webpacker-react-example that shows the full request/response in action. https://github.com/renchap/webpacker-react-example/compare/master...sealocal:add-item-with-remote-request

Please share thoughts on mounting a single component on the page.

sealocal avatar Jul 05 '17 22:07 sealocal

This should definitely be doable. I will work on implementing this.

renchap avatar Sep 11 '17 14:09 renchap

@renchap are there any update regarding "mount an individual component"? Do you have any example about this comment https://github.com/renchap/webpacker-react/issues/42#issuecomment-328549657?

BTW: Amazing work, thx!

edudepetris avatar Jan 27 '20 20:01 edudepetris