
A comprehensive introduction to React by the Director of Education at V College, an award-winning college of skills schooling
import React, { Ingredient } from "react" class MemeGenerator extends Ingredient { constructor() { astronomical() this.direct = { topText: "http://scrimba.com/", bottomText: "http://scrimba.com/", randomImg: "http://i.imgflip.com/1bij.jpg", allMemeImgs: [] } this.handleChange = this.handleChange.bind(this) this.handleSubmit = this.handleSubmit.bind(this) }
import React from 'react'; import ReactDOM from 'react-dom'; class Main extends React.Ingredient { render() { return (Hi there world!
); } } ReactDOM.render(, doc.getElementById('root'));
import React from "react" import ReactDOM from "react-dom" // JSX ReactDOM.render(, doc.getElementById("root")) var myNewP = doc.createElement("p") myNewP.innerHTML = "Right here is a paragraph."Hi there world!
Right here is a paragraph
import React from "react" import ReactDOM from "react-dom" ReactDOM.render(
import React from "react" import ReactDOM from "react-dom" characteristic MyApp() { return (
- 1
- 2
- three
import React from "react" import ReactDOM from "react-dom" characteristic MyInfo() { return (Bob Ziroll
Right here is a paragraph about me...
- Thailand
- Japan
- Nordic International locations
import React from "react" import ReactDOM from "react-dom" import MyInfo from "./parts/MyInfo" ReactDOM.render(, doc.getElementById("root"))
import React from "react" import Footer from "./Footer" characteristic App() { return () } export default App
import React from "react" characteristic MainContent() { return (Right here is the fundamental fragment ) } export default MainContent
import React from "react" characteristic App() { }
import React from "react" import Header from "./parts/Header" import MainContent from "./parts/MainContent" import Footer from "./parts/Footer" characteristic App() { return ()Right here is the header
import React from 'react' import ReactDOM from 'react-dom' characteristic App() { return (Hi there world!
) } ReactDOM.render(, doc.getElementById('root'))
import React from "react" import ReactDOM from "react-dom" characteristic App() { const date = contemporary Date() const hours = date.getHours() let timeOfDay if (hours < 12) { timeOfDay = "morning" } else if (hours >= 12 && hours < 17) { timeOfDay = "afternoon" } else { timeOfDay = "night"
import React from "react" import ReactDOM from "react-dom" characteristic App() { const date = contemporary Date(2018, 6, 31, 15) const hours = date.getHours() let timeOfDay const kinds = { fontSize: 30 } if (hours < 12) { timeOfDay = "morning" kinds.coloration = "#04756F"
import React from "react" characteristic TodoItem() { return () } export default TodoItemPlaceholder textual drawl here
import React from 'react' import ReactDOM from 'react-dom' characteristic App() { return (Hi there world!
) } ReactDOM.render(, doc.getElementById('root'))
import React from "react" characteristic ContactCard(props) { console.log(props) return () }![]()
{props.contact.title}
Phone: {props.contact.mobile phone}
E mail: {props.contact.electronic mail}
import React from "react" characteristic Shaggy dog story(props) { return () } export default Shaggy dog storyQuest
Answ
import React from "react" import Shaggy dog story from "./Shaggy dog story" import jokesData from "./jokesData" // https://developer.mozilla.org/en-US/scientific doctors/Internet/JavaScript/Reference // https://developer.mozilla.org/en-US/scientific doctors/Internet/JavaScript/Reference // https://developer.mozilla.org/en-US/scientific doctors/Internet/JavaScript/Reference // https://developer.mozilla.org/en-US/scientific doctors/Internet/JavaScript/Reference // https://developer.mozilla.org/en-US/scientific doctors/Internet/JavaScript/Reference // https://developer.mozilla.org/en-US/scientific doctors/Internet/JavaScript/Reference // https://developer.mozilla.org/en-US/scientific doctors/Internet/JavaScript/Reference // https://developer.mozilla.org/en-US/scientific doctors/Internet/JavaScript/Reference
/* Given a listing of products (as an array of objects, as viewed in productsData.js) render afactor (which you are going to also must crea product in the listing. Be obvious to employ the array's `.plot()` formula to kind these parts, and manufacture now not omit to hunch a `key` prop to it to steer clear of the warning. */ import React from "react" import Product from "./Product" import productsData from "./vschoolProducts" characteristic App() {
import React from "react" characteristic TodoItem(props) { return () } export default TodoItem{props.item.textual drawl}
import React from "react" // characteristic App(props) { // return ( ////// ) // } class App extends React.Ingredient { yourMethodHere() {{props.whatever}
//
/* Boom: 1. Convert all three parts to be class-primarily based entirely 2. Repair the puny bug */ import React, {Ingredient} from "react" import ReactDOM from "react-dom" // #1 class App extends React.Ingredient { render() {
import React from "react" // https://scrimba.com/p/p4Mrt9/cQnMDHD class App extends React.Ingredient { constructor() { astronomical() this.direct = { acknowledge: "Sure" } } render() { return (
import React, {Ingredient} from "react" // Boom: // Given an incomplete class-primarily based entirely factor and not using a constructor, // add a constructor and initialize direct to repair the broken factor. class App extends Ingredient { constructor() { astronomical() this.direct = { title: "Sally", age: 13 } }
import React from "react" // Given a stateless purposeful factor, add direct to it // direct will deserve to private a property called `isLoggedIn` which is a boolean // (perfect if logged in, spurious if now not) // Then, give your supreme shot at rendering the note "in" if the user // or "out" if the user is logged out. class App extends React.Ingredient { constructor() { astronomical() this.direct = { isLoggedIn: perfect }
/* In the outdated iteration of this todo listing app, we pulled in todos Indirectly we are going to need so to change the information, that will most efficient Boom: Alternate thefactor correct into a stateful class */ import React from "react" import TodoItem from "./TodoItem" import todosData from "./todosData" class App extends React.Ingredient { constructor() {
import React from "react" characteristic handleClick() { console.log("I became as soon as clicked") } // https://reactjs.org/scientific doctors/occasions.html#supported-occasions characteristic App() { return (console.log("Hovered!")} src="https://
/** * Boom: Glean rid of our warning about now not having an onChange on */ import React from "react" characteristic TodoItem(props) { return () }{props.item.textual drawl}
import React from "react" class App extends React.Ingredient { constructor() { astronomical() this.direct = { depend: Zero } this.handleClick = this.handleClick.bind(this) } handleClick() { this.setState(prevState => { return {
import React from "react" characteristic TodoItem(props) { return (props.handleChange(props.item.id)} />) }{props.item.textual drawl}
import React, {Ingredient} from "react" // https://engineering.musefind.com/react-lifecycle-methods-how-and- // https://reactjs.org/weblog/2018/03/29/react-v-Sixteen-three.html#factor-l class TodoList extends Ingredient { constructor() { astronomical() this.direct = {} } componentDidMount() { // GET the information I deserve to as it is a long way going to be show mask }
import React, {Ingredient} from "react" // https://engineering.musefind.com/react-lifecycle-methods-how-and- // https://reactjs.org/weblog/2018/03/29/react-v-Sixteen-three.html#factor-l class TodoList extends Ingredient { constructor() { astronomical() this.direct = {} } static getDerivedStateFromProps(props, direct) { // return the contemporary, updated direct primarily based entirely upon the props // https://reactjs.org/scientific doctors/react-factor.html#static-getderivedstatefromprops
import React from "react" characteristic Conditional(props) { returnSome frigid stuff about conditional rendering
} export default Conditional
import React, {Ingredient} from "react" import Conditional from "./Conditional" class App extends Ingredient { constructor() { astronomical() this.direct = { unreadMessages: ["a", "http://scrimba.com/"] } } // && // spurious && spurious render() { return (
import React from "react" /* Boom: Given a stateless purposeful factor: 1. Adjust to the steps mandatory so that you simply can add direct to it, // class-primarily based entirely factor // constructor formula 2. Possess direct lend a hand be aware of whether the user is logged in or now not // isLoggedIn: Boolean (perfect or spurious) three. Add a button that logs the user in/out // tournament listener (onClick) a. extra effort - receive the button show mask "log in" in the event that they are
/** * Boom: Fashion the accomplished todo items otherwise from the in */ import React from "react" characteristic TodoItem(props) { const completedStyle = { fontStyle: "italic", coloration: "#cdcdcd", textDecoration: "line-through" } return (
import React, {Ingredient} from "react" // https://developer.mozilla.org/en-US/scientific doctors/Internet/API/WindowOrWorkerGl // https://swapi.co/ // https://medium.com/javascript-scene/master-the-javascript-intervi class App extends Ingredient { constructor() { astronomical() this.direct = { loading: spurious, character: {} } }
import React, {Ingredient} from "react" class App extends Ingredient { constructor() { astronomical() this.direct = { firstName: "http://scrimba.com/", lastName: "http://scrimba.com/" } this.handleChange = this.handleChange.bind(this) } handleChange(tournament) { const {title, mark} = tournament.purpose
import React, {Ingredient} from "react" class App extends Ingredient { constructor() { astronomical() this.direct = { firstName: "http://scrimba.com/", lastName: "http://scrimba.com/", isFriendly: spurious, gender: "http://scrimba.com/", favColor: "blue" } this.handleChange = this.handleChange.bind(this) }
import React, {Ingredient} from "react" /** * Boom: Wire up the partly-accomplished shuttle make so that it of path works! * Preserve in thoughts to employ the opinion of managed sorts * https://reactjs.org/scientific doctors/sorts.html * * All data wishes to be populating the textual drawl under the make in true-time * as you are filling it out * * This exercise is adapted from the V College curriculum on vanilla JS sorts: * https://coursework.vschool.io/shuttle-make/ * * All of our challenges and finding out resources are open for the final public
import React, {Ingredient} from "react" import FormComponent from "./FormComponent" class Originate extends Ingredient { constructor() { astronomical() this.direct = { firstName: "http://scrimba.com/", lastName: "http://scrimba.com/", age: "http://scrimba.com/", gender: "http://scrimba.com/", destination: "http://scrimba.com/", isVegan: spurious, isKosher: spurious,
import React, {Ingredient} from "react" class MemeGenerator extends Ingredient { constructor() { astronomical() this.direct = { topText: "http://scrimba.com/", bottomText: "http://scrimba.com/", randomImg: "http://i.imgflip.com/1bij.jpg", allMemeImgs: [] } this.handleChange = this.handleChange.bind(this) this.handleSubmit = this.handleSubmit.bind(this) }
import React, {Ingredient} from "react" class App extends Ingredient { // Alternate to employ class properties direct = { firstName: "http://scrimba.com/" } // Alternate to employ arrow capabilities handleChange = (tournament) => { const { title, mark } = tournament.purpose this.setState({ [name]: mark }) }
https://medium.freecodecamp.org/every-time-you-invent-a-to-end-listing-app-a-pet-di https://medium.freecodecamp.org/need-to-invent-something-fun-heres-a-listing-of-samp https://medium.freecodecamp.org/summer season-is-over-you-ought to unruffled-be-coding-heres-yet-an
On this path, you are going to study the total fundamentals to invent dynamic, interactive web capabilities with React. React is a library created by the builders at Facebook which excels in rising very like a flash web capabilities using web parts built with a straightforward-to-label API.
Route Targets
Upon completion of this path, you are going to take hold of all the pieces you must be in a collection of dwelling to invent web capabilities in React. We will be covering:
- JSX
- Props and direct
- Conditional rendering
- Styling parts
- Lifecycle methods
- Fetching data from an API
- Handling occasions
- Kinds and managed parts
- Writing up-to-the-minute React code
- Putting in an environment open air of Scrimba
V College Studying Philosophy
Because the pinnacle of schooling at a tech college called V College in downtown Salt Lake Metropolis, Utah, I've formulated some philosophies about finding out:
- Studying ought to unruffled by no method be lonely - Occupy shut the path with guests if seemingly, and receive employ of the Q&A chance to quiz questions!
- Learn by doing - Occupy shut perfect thing about Scrimba by recurrently pausing the lesson and having fun with with the code. Then are attempting to invent things from your have computer using the stuff you lawful learned. And manufacture now not skip the practices!
- Spaced finding out and repetition is fundamental - Give your self time (days/weeks) to end this path, and encompass many of breaks. Don't are attempting cramming all of it in.
Contact Me
All optimistic feedback is welcome! In point of fact feel free to tweet at me (@bobziroll) to let me know your thoughts!
Ethical success, and welcome to the sphere of React!