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

Make props work in SSR #74

Closed
wants to merge 1 commit into from
Closed

Make props work in SSR #74

wants to merge 1 commit into from

Conversation

pyrossh
Copy link

@pyrossh pyrossh commented May 26, 2021

No description provided.

@Raynos
Copy link
Member

Raynos commented May 26, 2021

Can you give an example of how you would use this with props ?

@pyrossh
Copy link
Author

pyrossh commented May 27, 2021

Example when you do SSR with a component that has props,

const Tonic = require('tonic-ssr');

class MainPage extends Tonic {
  render() {
    return this.html`<div>
      ${this.props.name}
    </div>`;
  }
}

Tonic.add(MainPage);

const main = async () => {
  const mainPage = new MainPage({ name: '123' });
  const html = await mainPage.preRender();
  console.log('html', html);
};

main();
<html>
<head><style></style></head>
<body><div></div></body></html>

if props are initialized in the constructor we get,

<div>123</div>

Maybe this is a tonic-ssr related issue?

@pyrossh pyrossh closed this Jun 3, 2021
@heapwolf
Copy link
Member

heapwolf commented Jun 3, 2021

@pyros2097 was there a resolution to this?

@pyrossh
Copy link
Author

pyrossh commented Jun 4, 2021

There are other ways to solve this like mainPage.props = props. It's not specifically needed in the constructor so I decided to close it.

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

Successfully merging this pull request may close these issues.

None yet

3 participants