reactjs / express-react-views

This is an Express view engine which renders React components on server. It renders static markup and *does not* support mounting those views on the client.
Other
2.73k stars 261 forks source link

Adding on click to generated html and a question about dynamic demo #132

Closed Return-1 closed 6 years ago

Return-1 commented 6 years ago

I am aware this lib is SSR and does not mount any js in the client.

Assuming i wanted to attach an onClick handler on part of my generated html. Right now what im doing is adding ids to my components and then through my js, attach listeners to them. Is there a better way? I would assume adding the onclick property would also add it to the html but it seems to be stripped.

What follows is not really an issue ( and somewhat related to the issue above), if there's a different place to post this do redirect me.

Even though this lib's purpose is to SSR im seeing this in the dynamic demo which employs setState and a custom onChange class method. Am i missing something? https://github.com/reactjs/express-react-views/blob/master/examples/dynamic/views/Content.js

Thanks a lot

zpao commented 6 years ago

The dynamic demo is pretty hacky, I wouldn't rely on the patterns there.

As you noted, this is for SSR. onClick is a client prop and doesn't end up in the generated JS. id and your own JS is an option.

Otherwise, I'd recommend not using this project. Something like https://nextjs.org/ is probably what most people want today.