File: jsx

package info (click to toggle)
ruby-rouge 4.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,836 kB
  • sloc: ruby: 38,168; sed: 2,071; perl: 152; makefile: 8
file content (81 lines) | stat: -rw-r--r-- 1,981 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<header className="App-header">
  Hello React!
</header>

var myDivElement = <div className="foo" />;
ReactDOM.render(myDivElement, document.getElementById('example'));

var MyComponent = React.createClass({/*...*/});
var myElement = <MyComponent someProperty={true} />;
ReactDOM.render(myElement, document.getElementById('example'));

var myElement = <MyComponent someProperty={{a:true}.a} />;
var myElement = <MyComponent someProperty={function() {
  var x = { a: true };
  return x.a;
}} />

thing.otherThing<MyComponent.property // comment - this is comparison
var myElement = <MyComponent thing={thing.otherThing>2}>
  hello, world!
</MyComponent>

var content = <Container>{window.isLoggedIn ? <Nav /> : <Login />}</Container>;

// These two are equivalent in JSX for disabling a button
<input type="button" disabled />;
<input type="button" disabled={true} />;

// And these two are equivalent in JSX for not disabling a button
<input type="button" />;
<input type="button" disabled={false} />;

var App = (
  <Form>
    <Form.Row>
      <Form.Label />
      <Form.Input />
    </Form.Row>
  </Form>
);

var content = (
  <Nav>
    {/* child comment, put {} around */}
    a slash-star that isn't a comment because this is html: /*
    <Person
      /* multi
         line
         comment */
      name={window.isLoggedIn ? window.name : ''} // end of line comment
    />
  </Nav>
);

var thing = <A b={function() { var c = <D e={true}>&quot;</D>; }()}/>

class LikeButton extends React.Component {
  constructor() {
    super();
    this.state = {
      liked: false
    };
    this.handleClick = this.handleClick.bind(this);
  }
  handleClick() {
    this.setState({liked: !this.state.liked});
  }
  render() {
    const text = this.state.liked ? 'liked' : 'haven\'t liked';
    return (
      <div onClick={this.handleClick}>
        You {text} this. Click to toggle.
      </div>
    );
  }
}

ReactDOM.render(
  <LikeButton />,
  document.getElementById('example')
);