react-summary
Use NPM or Yarn for package management
Use
create-react-appto set up a new projectnpm install --global create-react-app
Use NPM commands to build and run the application
npm startfor developmentnpm buildto build for deployment
React components are functions that generate page elements on the client
Use JSX to embed HTML in JavaScript (in HTML in JavaScript in...)
Requires transpilation with Babel to convert to pure JavaScript
Properties of HTML pseudo-element passed to React function in
propsWrite
<Greet company="Rangle.io"/>Calls
Greet(props={company: "Rangle.io"})Must return a single top-level HTML element
But that can contain many other elements generated by other components
Use
prop-typesto specify whatpropsmust containUse
classNameinstead ofclassto specifyclassproperty of HTMLTwo types of components:
Stateless (pure functional) components for display only
Stateful components (often classes) to contain state and handle events
Stateful components maintain state in a member variable called
stateInitialize with a single object in constructor
Always update with
this.setState({key: value, ...})Only need to pass in elements that are changing
setStatetriggers re-rendering of nested elementsReact does work behind the scenes to minimize actual redrawing
Lifecycle methods of class components are called at specific moments
constructorwhen component created (as usual)componentDidMountwhen component added to DOMcomponentWillMountcalled during server renderingcomponentWillUnmountwhen component being removedshouldComponentUpdatecalled after a component's props or state has changed.componentWillUpdateandcomponentDidUpdatecalled before and after a component re-renderscomponentWillReceivePropscalled before a component has received props whose values have changed
Last updated
Was this helpful?