Archive | template literal

RSS feed for this section

HTML Templates via JavaScript Template Literals

You know those super cool backticks-for-strings in new JavaScript?

let emotion = `happy`;
let sentence = `Chris is feeling ${emotion}`;

Besides the variable interpolation in there being mighty handy, the do multi-line strings wonderfully, making them great for chunks of HTML:

const some_html = `
<div class="module>
<h2>${data.title}</h2>
<p>${data.content}</p>
</div>
`;

That doesn’t look overly different than JSX does it?! Maybe we’d do something like that as a React component:

class MyModule extends React.Component {
render() {
return
<div class="module">


HTML Templates via JavaScript Template Literals is a post from CSS-Tricks

Reactive UI’s with VanillaJS – Part 2: Class Based Components

In Part 1, I went over various functional-style techniques for cleanly rendering HTML given some JavaScript data. We broke our UI up into component functions, each of which returned a chunk of markup as a function of some data. We then composed these into views that could be reconstructed from new data by making a single function call.

This is the bonus round. In this post, the aim will be to get as close as possible to full-blown, class-based …


Reactive UI’s with VanillaJS – Part 2: Class Based Components is a post from CSS-Tricks

Reactive UI’s with VanillaJS – Part 1: Pure Functional Style

Last month Chris Coyier wrote a post investigating the question, “When Does a Project Need React?” In other words, when do the benefits of using React (acting as a stand-in for data-driven web frameworks in general), rather than server-side templates and jQuery, outweigh the added complexity of setting up the requisite tooling, build process, dependencies, etc.? A week later, Sacha Greif wrote a counterpoint post arguing why you should always use such a framework for every type of web project. …


Reactive UI’s with VanillaJS – Part 1: Pure Functional Style is a post from CSS-Tricks