Skip to content
This repository was archived by the owner on Feb 19, 2022. It is now read-only.

add template literals example #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions example-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Destructuring from "./examples/destructuring/index.jsx";
import Generators from "./examples/generators/index.jsx";
import ObjectLiterals from "./examples/object-literals/index.jsx";
import SpreadOperator from "./examples/spread-operator/index.jsx";
import TemplateLiterals from "./examples/template-literals/index.jsx";

export default [{
name: "Arrow functions",
Expand All @@ -27,4 +28,7 @@ export default [{
}, {
name: "Spread operator",
example: SpreadOperator
}, {
name: "Template literals",
example: TemplateLiterals
}];
6 changes: 6 additions & 0 deletions examples/template-literals/a.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const firstName = "Foo";
const lastName = "Bar";

const a = `Full name: ${firstName} ${lastName}`;

console.log(a);
20 changes: 20 additions & 0 deletions examples/template-literals/index.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react/addons';
import Playground from 'component-playground';
import Code from '../../code.jsx';
import a from 'raw!./a.example';

export default React.createClass({
render() {
return (
<div>
<p>
Template literals improve the experience of constructing strings by allowing embedded expressions.
</p>
<p>
The output of <Code>{'`My name is ${name}`'}</Code> is equivalent to <Code>{'"My name is " + name'}</Code>
</p>
<Playground codeText={a} es6Console={true} scope={{}} />
</div>
);
}
});