markdalgleish / static-site-generator-webpack-plugin

Minimal, unopinionated static site generator powered by webpack
MIT License
1.61k stars 97 forks source link

Is it possible to implement client side logic (using React) in generated pages? #112

Closed haszari closed 7 years ago

haszari commented 7 years ago

Apologies if this is a silly question.. is it possible to use react for client-side logic in the generated site?

For example, have a click handler for a button which logs to console (or sets state).

I can imagine why this might not be supported. Can anyone suggest good ways to implement simple client-side logic/behaviour in my generated site?

eloytoro commented 7 years ago

Yes all you have to do is include the scripts in the generated HTML

haszari commented 7 years ago

Thanks – works great. I also needed to call renderToString instead of renderToStaticMarkup (of course).

dvidsilva commented 7 years ago

Just in case someone sees this in the future, you have to add some extra code to make it happen. This article helped me fix the issue on my project: https://jaketrent.com/post/react-routing-static-site-browser/