Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to use this to export a function that calls ReactDOM.render, rather than rendering automatically? #334

Closed
n8jadams opened this issue Dec 21, 2020 · 0 comments

Comments

@n8jadams
Copy link

n8jadams commented Dec 21, 2020

I've got my project build from this repo working correctly in calling ReactDOM.render, but oddly enough when I move the .render call into a function, it isn't working as expected:

import React from 'react'
import ReactDOM from 'react-dom'

function Component(): void {
  return <div>Hello world from React!</div>
}

export function authorNavBootstrap(): void {
	const mountNode = document.getElementById('my-react-root')
	ReactDOM.render(
		<Component />,
		mountNode
	)
}

When I import this into a separate snowpack project (using file:../path/to/lib) and in my src js I import '@my-namespace/my-library', the React app is rendered for some reason... And even worse, when I import { authorNavBootstrap } from '@my-namespace/my-library'; authorNavBootstrap() I get this error:

Uncaught SyntaxError: The requested module './web_modules/@my-namespace/my-library.js' does not provide an export named 'authorNavBootstrap'...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant