Learn the fundamentals of React, including simple and class components, state, props, and submitting form data.
Function Component, Class Component
<div id="root"></div> |
// function component | |
function Welcome(props) { | |
return <h1>Hello, {props.name}!</h1>; | |
} | |
// class component | |
class Welcome2 extends React.Component { | |
render(){ | |
return <h1>Hello, {this.props.name}!</h1>; | |
} | |
} | |
const element = ( | |
<div> | |
<Welcome name="Sara"/> | |
<Welcome2 name="Li"/> | |
</div> | |
); | |
ReactDOM.render( | |
element, | |
document.getElementById('root') | |
); |
<script src="https://unpkg.com/react/umd/react.development.js"></script> | |
<script src="https://unpkg.com/react-dom/umd/react-dom.development.js"></script> |