Přejít na menu

React.js tips

Správa článků

Vyhledávání Vyhledávání
8.11.2015 19:28
,
Počet přečtení: 815
Obrázek ke článku React.js tipsTips for using React.js framework.

Basic tutorial on React homepage

Basic example: Hello world

(More basic examples)

<!DOCTYPE HTML>
<html>
  <head>
    <title>React Hello World</title>
  </head>
  <body>
    <!-- Use the compilation in production instead of JSX -->
    <script src="http://fb.me/react-0.12.2.min.js"></script>
    <script src="http://fb.me/JSXTransformer-0.12.2.js"></script>
    <script type="text/jsx">
      var HelloMessage = React.createClass({
      render: function () {
        return <h1>Hello {this.props.message}!</h1>;
      }
    });
React.render(<HelloMessage message="World" />, document.body);
    </script>
  </body>
</html>

Rendering tips

Class name tag attribute

The attribute must be named as className (simple class doest not work).

ReactDOM.render(<div className="my-class">Hello World!</div>, mountNode);

Inline styles

Could not be written as the string, but must be declared in the array variable.

var divStyle = {color: 'white'};
ReactDOM.render(<div style={divStyle}>Hello World!</div>, mountNode);

Array variable

render: function() {
        return (
            <ul className="Uli">
            {this.props.data.map(function(value) {
                return <li key={value}>{value}</li>
            })}
            </ul>
        )
    }

Vytvořil 8. listopadu 2015 v 19:40:50 mira. Upravováno 41x, naposledy 8. listopadu 2015 ve 20:09:00, mira


Diskuze ke článku

Vložení nového komentáře
*
*
*