--- title: React.js category: React layout: 2017/sheet --- {%raw%} Getting started --------------- {:.-three-column} ### Getting started ```jsx class MyComponent extends React.Component { render () { return
Hello {this.props.name}
} } ``` ```jsx const el = document.body ReactDOM.render(, el) ``` Use the [React.js jsfiddle](http://jsfiddle.net/reactjs/69z2wepo/) to start hacking. (or the unofficial [jsbin](http://jsbin.com/yafixat/edit?js,output)). ### Functional components ```jsx function MyComponent ({ name }) { return
Hello {name}
} ``` Functional components have no state. Also, their `props` are passed as the first parameter to a function. ### Nesting ```jsx class Info extends React.Component { render () { const { avatar, username } = this.props return
} } ``` Nest components to separate concerns. See: [multiple components](http://facebook.github.io/react/docs/multiple-components.html) ### Component API ```jsx this.forceUpdate() this.isMounted() this.setState({ ... }) this.replaceState({ ... }) this.state this.props ``` These are methods available for `Component` instances. See [Component API](http://facebook.github.io/react/docs/component-api.html). ### Component specs | Method | What | | ---- | ---- | | [`render()`](http://facebook.github.io/react/docs/component-specs.html#render) | | | ---- | ---- | | [`getInitialState()`](http://facebook.github.io/react/docs/component-specs.html#getinitialstate) | | | [`getDefaultProps()`](http://facebook.github.io/react/docs/component-specs.html#getdefaultprops) | | | ---- | ---- | | [`mixins: [ ... ]`](http://facebook.github.io/react/docs/component-specs.html#mixins) | Mixins ... [more](#mixins) | | [`propTypes: { ... }`](http://facebook.github.io/react/docs/component-specs.html#proptypes) | Validation ... [more](#property-validation) | | [`statics: { ... }`](http://facebook.github.io/react/docs/component-specs.html#statics) | Static methods | | [`displayName: "..."`](http://facebook.github.io/react/docs/component-specs.html#displayname) | Automatically filled by JSX | {:.greycode.no-head} Methods and properties you can override. See [component specs](http://facebook.github.io/react/docs/component-specs.html). ### Properties ```html