zoukankan      html  css  js  c++  java
  • [React] React Fundamentals: Build a JSX Live Compiler

    we want to have the ability to write JSX and see the output live in the browser. 

    <!doctype html>
    <html lang="en">
    <head>
        <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
        <link rel="stylesheet" href="style.css"/>
        <script src="//fb.me/react-0.13.3.js"></script>
        <script src="//fb.me/JSXTransformer-0.13.3.js"></script>
        <meta charset="utf-8">
        <title>Compiler</title>
    </head>
    <body>
    <script type="text/jsx">
        /** @jsx React.DOM */
    
        var App = React.createClass({
            getInitialState: function() {
                return {
                    input: '',
                    output: '',
                    err: ''
                }
            },
            update: function(e) {
                try{
                    var input = this.refs.htmlCode.getDOMNode().value;
                    this.setState({
                        output: JSXTransformer.transform(input).code,
                        err: ''
                    })
                }catch(err){
                    this.setState({
                        err: err.message
                    })
                }
            },
            render: function() {
                return (
                        <div className="container">
                            <div className="row">
                                <div className="alert alert-danger">
                                    &nbsp;{this.state.err}
                                </div>
                            </div>
                            <div className="row">
                                <textarea type="text" className="col-md-6 input-lg"
                                          ref="htmlCode"
                                          defaultValue={this.state.input} onChange={this.update}></textarea>
                                <pre className="col-md-6 input-lg">{this.state.output}</pre>
                            </div>
                        </div>
                )
            }
        });
    
        React.render(<App />, document.body);
    </script>
    </body>
    </html>
  • 相关阅读:
    Explain 索引优化分析
    组合索引与前缀索引
    MySQL 索引的类型
    MySQL 字符集及校验规则
    MySQL 连接查询
    DQL 数据查询语言
    DML 数据操纵语言
    DCL 数据控制语言
    DDL 数据定义语言
    蓝桥杯大学B组省赛2020模拟赛(一)题解与总结
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4761416.html
Copyright © 2011-2022 走看看