100% found this document useful (1 vote)
2K views

Reactjs Cheat Sheet

React is a JavaScript library for building user interfaces. It allows building of user interface components called React components that can be rendered to the DOM. React components can be stateless functions or class components that use local state and lifecycle hooks. Components receive data through properties called props and conditionally render elements and CSS classes based on their state or props.

Uploaded by

Sabrina Moraru
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
2K views

Reactjs Cheat Sheet

React is a JavaScript library for building user interfaces. It allows building of user interface components called React components that can be rendered to the DOM. React components can be stateless functions or class components that use local state and lifecycle hooks. Components receive data through properties called props and conditionally render elements and CSS classes based on their state or props.

Uploaded by

Sabrina Moraru
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

React Cheat Sheet DEMO: https://s.codepen.

io/ericnakagawa/debug/ALxakj
GITHUB: https://github.com/facebook/react
DOCUMENTATION: https://facebook.github.io/react/docs/
A javascript library for building user interfaces. CDN: https://cdnjs.com/libraries/react/

Hello World ES6 Class Conditional Rendering


// conditional rendering of elements and CSS class
// Import React and ReactDOM // use class for local state and lifecycle hooks
render() {
import React from 'react' class App extends React.Component {
const {isLoggedIn, username} = this.state;
import ReactDOM from 'react-dom'
return (
constructor(props) {
<div className={`login ${isLoggedIn ? 'is-in'
// Render component into the DOM - only once per app // fires before component is mounted
: 'is-out'}`}>
ReactDOM.render( super(props); // makes this refer to this component
{
<h1>Hello, world!</h1>, this.state = {date: new Date()}; // set state
!!isLoggedIn ?
document.getElementById('root') }
<p>Logged in as {username}.</p>
); render() {

Core
:
return (
<p>Logged out.</p>
Stateless Components <h1>
}
It is {this.state.date.toLocaleTimeString()}.
</div>
// Stateless React Component </h1>
)
const Headline = () => { )
}
return <h1>React Cheat Sheet</h1> }
// CodePen Demo: http://bit.ly/react-if-statements
}
componentWillMount() {
// Component that receives props // fires immediately before the initial render Tools and Resources
const Greetings = (props) => { }
return <p>You will love it {props.name}.</p> componentDidMount() { // Create React App
} // fires immediately after the initial render http://bit.ly/react-app
} // React Dev Tools for Chrome
// Component must only return ONE element (eg. DIV) componentWillReceiveProps() { http://bit.ly/react-dev-tools
const Intro = () => { // fires when component is receiving new props // React Code Snippets for Visual Studio Code
return ( } http://bit.ly/react-es6-snippets-for-vscode
<div> shouldComponentUpdate() { // Babel for Sublime Text 3
Lifecycle Methods

<Headline /> // fires before rendering with new props or state http://bit.ly/babel-sublime
<p>Welcome to the React world!</p> }
<Greetings name=”Petr” /> componentWillUpdate() {
</div> // fires immediately before rendering Free Online Course

}
)
}
// with new props or state
React.js 101
componentDidUpdate() { The Quickest Way To Get
ReactDOM.render( // fires immediately after rendering with new P or S
<Intro />, }
Started With React.js
document.getElementById('root') componentWillUnmount() {
); // fires immediately before component is unmounted http://bit.ly/get-react-101
// from DOM (removed)
// Components and Props API - http://bit.ly/react-props }
// CodePen Demo: http://bit.ly/react-simple } Coming Soon!
// CodePen Demo: http://bit.ly/react-es6-class

Created with ♥ by Petr Tichy, happy coding! v0.8 https://www.ihatetomatoes.net

You might also like