Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hugo with React?

Is it possible/ideal to use something like Hugo with React? I am aware of Gatsby, but would Hugo work as well. I have limited knowledge of combining the two but my understanding would be that Hugo would be used for all your templating and static web pages and then React would be used for the web application type of things, and a headless CMS somewhere in there? Can someone with experience comment why Hugo or Gatsby are sometimes good to use with React? Or an overview of the relationship between the frameworks?

like image 737
J. E Avatar asked Nov 15 '18 15:11

J. E


People also ask

Does Hugo work with React?

Hugo, that I use for my static site, does not directly have support for transpiling React. But with a few small steps you can make React transpiling as a part of your Hugo build and use React for your user experiences.

Can I use JavaScript with Hugo?

Hugo Pipes can process JavaScript files with ESBuild. Any JavaScript resource file can be transpiled and “tree shaken” using js. Build which takes for argument either a string for the filepath or a dict of options listed below.

Is React good for CMS?

React is amazing not only because it's blazing fast but also most importantly for its component-based architecture. When using a CMS, React unleashes all its power mainly because of this architecture since the developer will design and develop really reusable components.

Does React interact with DOM?

React will call the ref callback with the DOM element when the component mounts, and call it with null when it unmounts. Refs are guaranteed to be up-to-date before componentDidMount or componentDidUpdate fires.


1 Answers

Is it possible/ideal to use something like Hugo with React? I am aware of Gatsby, but would Hugo work as well.

We used Hugo with React (create-react-app) at https://www.electrade.app. All pages serve to hugo static pages, but if you navigate to /quote, the react SPA loads and you're in dynamic land. So yes, Hugo works as well, but you'll have 2 languages and 2 syntaxes.

combining the two [...] my understanding would be that Hugo would be used for all your templating and static web pages and then React would be used for the web application type of things

Exactly.

Can someone with experience comment why Hugo or Gatsby are sometimes good to use with React? Or an overview of the relationship between the frameworks?

  • Hugo is written in Go and builds vanilla static HTML. Example: a blog, but you only need to write the header and footer once.
  • React is written in Javascript and is a front-end library to build dynamic interfaces. A React site will usually serve you an empty index.html file and a Javascript file, which will then run and fill the index.html file with content dynamically in your browser. Example: Facebook Newsfeed that's different every time it loads.
  • But what if you want to write the example blog above, also only writing the header and footer once, but are used to React syntax? If you use normal React, your blog will download an empty index.html file and fill it with your blog in Javascript. This is not good for SEO and load times, among other things. If you want to still have it compile down to vanilla static HTML – that's what Gatsby is for.
like image 177
Niko Dunk Avatar answered Oct 08 '22 18:10

Niko Dunk