Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

React.js Cheatsheet: A Comprehensive Guide to React Development, Cheat Sheet of Software Development

This cheatsheet provides a concise and comprehensive overview of react.js, covering essential concepts, syntax, and best practices. It includes sections on properties, nesting, defaults, lifecycle, hooks, references, dom events, jsx patterns, property validation, and more. The cheatsheet is designed to be a quick reference for developers of all levels, from beginners to experienced professionals.

Typology: Cheat Sheet

2024/2025

Uploaded on 12/17/2024

luther-anderson
luther-anderson 🇺🇸

1 document

1 / 17

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
React.js cheatsheet
React is a JavaScript library for building user interfaces. This guide targets React v15 to v16.
Components
import React from 'react'
import ReactDOM from 'react-dom'
class Hello extends React.Component {
render () {
return <div className='message-box'>
Hello {this.props.name}
</div>
}
}
const el = document.body
ReactDOM.render(<Hello name='John' />, el)
Use the React.js jsfiddle to start hacking. (or the unofficial jsbin)
Import multiple exports
import React, {Component} from 'react'
import ReactDOM from 'react-dom'
class Hello extends Component {
...
}
DEVHINTS.IO
Edit
Deliver website design projects
30% faster with BugHerd.
ads via Carbon
12/16/24, 10:05 PM
React.js cheatsheet
https://devhints.io/react
1/17
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download React.js Cheatsheet: A Comprehensive Guide to React Development and more Cheat Sheet Software Development in PDF only on Docsity!

React.js cheatsheet

React is a JavaScript library for building user interfaces. This guide targets React v15 to v16.

Components

import React from 'react' import ReactDOM from 'react-dom' class Hello extends React.Component { render () { return

Hello {this.props.name}

} } const el = document.body ReactDOM.render(, el) Use the React.js jsfiddle to start hacking. (or the unofficial jsbin)

Import multiple exports

import React, {Component} from 'react' import ReactDOM from 'react-dom' class Hello extends Component { ... } DEVHINTS.IO Edit Deliver website design projects 30% faster with BugHerd. ads via Carbon

Properties

See: Inline styles

Inner HTML

function markdownify() { return "

...

"; }

See: Dangerously set innerHTML

Lists

Always supply a key property.

Conditionals

{showMyComponent ? : }

Short-circuit evaluation

{showPopup && } ... class TodoList extends Component { render () { const { items } = this.props return

    {items.map(item => )}

} }

Portals

This renders this.props.children into any location in the DOM. See: Portals

Hydration

Use ReactDOM.hydrate instead of using ReactDOM.render if you’re rendering over the output of ReactDOMServer. See: Hydrate render () { return React.createPortal( this.props.children, document.getElementById('menu') ) } const el = document.getElementById('app') ReactDOM.hydrate(, el) Property validation

PropTypes

import PropTypes from 'prop-types' See: Typechecking with PropTypes any Anything Basic string number func Function bool True or false Enum oneOf(any) Enum types oneOfType(type array) Union Array array arrayOf(…) Object object objectOf(…) Object with values of a certain type instanceOf(…) Instance of a class shape(…) Elements element React element node DOM node Required (···).isRequired Required

Basic types

MyComponent.propTypes = { email: PropTypes.string, seats: PropTypes.number, callback: PropTypes.func, isClosed: PropTypes.bool, any: PropTypes.any }

Custom validation

MyCo.propTypes = { customProp: (props, key, componentName) => { if (!/matchme/.test(props[key])) { return new Error('Validation failed!') } } }

0 Comments for this cheatsheet. Write yours!

Search 357+ cheatsheets

Over 357 curated cheatsheets, by developers for developers.Over 357 curated cheatsheets, by developers for developers.

Devhints homeDevhints home

Other React cheatsheets

Redux

cheatsheet

Enzyme

cheatsheet

Enzyme v

cheatsheet

Awesome Redux

cheatsheet

Top cheatsheets

Elixir

cheatsheet

ES2015+

cheatsheet

Vim

cheatsheet

Vimdiff

cheatsheet Also see React website(reactjs.org) React cheatsheet(reactcheatsheet.com) Awesome React(github.com) React v0.14 cheatsheetLegacy version

Flux architecture

cheatsheet

React-router

cheatsheet

Vim scripting

cheatsheet

Vue.js

cheatsheet