@@ -317,26 +317,34 @@ const markdownStyles = {
317
317
318
318
// TODO Move these hard-coded examples into example files and out of the template?
319
319
// Alternately, move them into the markdown and transform them during build?
320
+ const name = Math . random ( ) > .5 ? 'John' : 'Jane' ;
320
321
const HELLO_COMPONENT = `
321
322
class HelloMessage extends React.Component {
322
323
render() {
323
- return <div>Hello {this.props.name}</div>;
324
+ return (
325
+ <div>
326
+ Hello {this.props.name}
327
+ </div>
328
+ );
324
329
}
325
330
}
326
331
327
- ReactDOM.render(<HelloMessage name="Devin" />, mountNode);
332
+ ReactDOM.render(
333
+ <HelloMessage name="${ name } " />,
334
+ mountNode
335
+ );
328
336
` . trim ( ) ;
329
337
330
338
const TIMER_COMPONENT = `
331
339
class Timer extends React.Component {
332
340
constructor(props) {
333
341
super(props);
334
- this.state = {secondsElapsed : 0};
342
+ this.state = { seconds : 0 };
335
343
}
336
344
337
345
tick() {
338
346
this.setState((prevState) => ({
339
- secondsElapsed : prevState.secondsElapsed + 1
347
+ seconds : prevState.seconds + 1
340
348
}));
341
349
}
342
350
@@ -350,7 +358,9 @@ class Timer extends React.Component {
350
358
351
359
render() {
352
360
return (
353
- <div>Seconds Elapsed: {this.state.secondsElapsed}</div>
361
+ <div>
362
+ Seconds: {this.state.seconds}
363
+ </div>
354
364
);
355
365
}
356
366
}
@@ -362,9 +372,9 @@ var TODO_COMPONENT = `
362
372
class TodoApp extends React.Component {
363
373
constructor(props) {
364
374
super(props);
375
+ this.state = { items: [], text: '' };
365
376
this.handleChange = this.handleChange.bind(this);
366
377
this.handleSubmit = this.handleSubmit.bind(this);
367
- this.state = {items: [], text: ''};
368
378
}
369
379
370
380
render() {
@@ -373,20 +383,25 @@ class TodoApp extends React.Component {
373
383
<h3>TODO</h3>
374
384
<TodoList items={this.state.items} />
375
385
<form onSubmit={this.handleSubmit}>
376
- <input onChange={this.handleChange} value={this.state.text} />
377
- <button>{'Add #' + (this.state.items.length + 1)}</button>
386
+ <input
387
+ onChange={this.handleChange}
388
+ value={this.state.text}
389
+ />
390
+ <button>
391
+ Add #{this.state.items.length + 1}
392
+ </button>
378
393
</form>
379
394
</div>
380
395
);
381
396
}
382
397
383
398
handleChange(e) {
384
- this.setState({text: e.target.value});
399
+ this.setState({ text: e.target.value });
385
400
}
386
401
387
402
handleSubmit(e) {
388
403
e.preventDefault();
389
- var newItem = {
404
+ const newItem = {
390
405
text: this.state.text,
391
406
id: Date.now()
392
407
};
@@ -417,15 +432,15 @@ class MarkdownEditor extends React.Component {
417
432
constructor(props) {
418
433
super(props);
419
434
this.handleChange = this.handleChange.bind(this);
420
- this.state = {value: 'Type some *markdown* here!'};
435
+ this.state = { value: 'Type some *markdown* here!' };
421
436
}
422
437
423
438
handleChange(e) {
424
- this.setState({value: e.target.value});
439
+ this.setState({ value: e.target.value });
425
440
}
426
441
427
442
getRawMarkup() {
428
- var md = new Remarkable();
443
+ const md = new Remarkable();
429
444
return { __html: md.render(this.state.value) };
430
445
}
431
446
0 commit comments