Preact-cli: How to mount a preact-cli generated app to a custom div id?

Created on 7 Jan 2018  路  2Comments  路  Source: preactjs/preact-cli


Do you want to request a feature or report a bug?
Feature
What is the current behavior?
The cli does not allow mounting app to a specific id

If this is a feature request, what is motivation or use case for changing the behavior?
In some cases, we want to mount an app to a specific div id="". In my case, I already have a static site, but I want to create a part which will be a Preact app. This will preserve the advantages of the static site I have as well as add the new features Preact comes with.

Most helpful comment

You can also opt-out of preact-cli's automatic rendering - just don't export anything from src/index.js:

import App from './components/app';
import { render } from 'preact';

// render into some specific element:
render(<App />, document.getElementById('my-div-id'))

All 2 comments

dupe of https://github.com/developit/preact-cli/issues/264

have you looked at preact-habitat? might suit your needs. https://github.com/zouhir/preact-habitat

You can also opt-out of preact-cli's automatic rendering - just don't export anything from src/index.js:

import App from './components/app';
import { render } from 'preact';

// render into some specific element:
render(<App />, document.getElementById('my-div-id'))
Was this page helpful?
0 / 5 - 0 ratings