react-summary
Use NPM or Yarn for package management
Use
create-react-app
to set up a new projectnpm install --global create-react-app
Use NPM commands to build and run the application
npm start
for developmentnpm build
to 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
props
Write
<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-types
to specify whatprops
must containUse
className
instead ofclass
to specifyclass
property 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
state
Initialize with a single object in constructor
Always update with
this.setState({key: value, ...})
Only need to pass in elements that are changing
setState
triggers re-rendering of nested elementsReact does work behind the scenes to minimize actual redrawing
Lifecycle methods of class components are called at specific moments
constructor
when component created (as usual)componentDidMount
when component added to DOMcomponentWillMount
called during server renderingcomponentWillUnmount
when component being removedshouldComponentUpdate
called after a component's props or state has changed.componentWillUpdate
andcomponentDidUpdate
called before and after a component re-renderscomponentWillReceiveProps
called before a component has received props whose values have changed
Last updated
Was this helpful?