Thursday, 10 May 2018

react 1 code


<head>
    <script src="https://unpkg.com/react@16/umd/react.development.js"></script>
    <script src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
class App extends React.Component {
    render() {
        return (
            <div>
                <CommentBox data={data} />
                <CommentForm />
            </div>
        );
    }
}

function CommentBox(props) {
    return (
        <div>
            <p>I am a Comment Box</p>
            <CommentList data={props.data}/>
        </div>
    );
}

function CommentList(props) {

    const commentNodes = props.data.map((item)=>
        <li key={item.id}>
            {item.author}, {item.text}
            </li>
        );

    return (
        <div>
            <p>I am a List Box</p>
            <ol>{commentNodes}</ol>
       
        </div>
    );
}

function CommentForm() {
    return <p>I am a Comment Form</p>
}

function Comment(props) {
    return (
        <div>
            <p>{props.author}</p>
            {props.children}
        </div>
    );
}

const data = [
    { id: 1, author: "Daniel Lo Nigro", text: "Hello ReactJS.NET World!" },
    { id: 2, author: "Pete Hunt", text: "This is one comment" },
    { id: 3, author: "Jordan Walke", text: "This is *another* comment" }
];

ReactDOM.render(
    <App />,
    document.getElementById('root'));

</script>
</body>

No comments:

Post a Comment