import React.Component from 'react'import [ Component ] from 'react'import Component from 'react'import { Component } from 'react'const person = (firstName, lastName) =>
{
first: firstName,
last: lastName
}
console.log(person("Jill", "Wilson"))
import React, { useState } from 'react';
const name = 'Rachel';
const age = 31;
const person = { name, age };
console.log(person);
{ {name: "Rachel", age: 31} }{name: "Rachel", age: 31}{person: "Rachel", person: 31}{person: {name: "Rachel", age: 31}}const topics = ['cooking', 'art', 'history'];
const first = ["cooking", "art", "history"]const [] = ["cooking", "art", "history"]const [, first]["cooking", "art", "history"]const [first] = ["cooking", "art", "history"]const [, , animal] = ['Horse', 'Mouse', 'Cat'];
console.log(animal);
<Message {...props} />
<Route path="/:id" />
function Dish() {
return <h1>Mac and Cheese</h1>;
}
ReactDOM.render(<Dish />, document.getElementById('root'));
divh1React.createElement('h1', null, "What's happening?");
<h1 props={null}>What's happening?</h1><h1>What's happening?</h1><h1 id="component">What's happening?</h1><h1 id="element">What's happening?</h1>function MyComponent() {
return (
<Suspense>
<div>
<Message />
</div>
</Suspense>
);
}
const message = 'Hi there';
const element = <p>{message}</p>;
React.memoReact.splitReact.lazyReact.fallbackA. <button onClick={this.handleClick}>Click Me</button>
B. <button onClick={event => this.handleClick(event)}>Click Me</button>
function Dish(props) {
return (
<h1>
{props.name} {props.cookingTime}
</h1>
);
}
function Dish([name, cookingTime]) { return <h1>{name} {cookingTime}</h1>; }function Dish({name, cookingTime}) { return <h1>{name} {cookingTime}</h1>; }function Dish(props) { return <h1>{name} {cookingTime}</h1>; }function Dish(...props) { return <h1>{name} {cookingTime}</h1>; }설명: children in JSX
const Heading = () => {
<h1>Hello!</h1>;
};
[e.target.id] 부분을 무엇이라고 부를까?handleChange(e) {
this.setState({ [e.target.id]: e.target.value })
}
class Clock extends React.Component {
render() {
return <h1>Look at the time: {time}</h1>;
}
}
ReactReactDOMRenderDOMclass clock extends React.Component {
render() {
return <h1>Look at the time: {this.props.time}</h1>;
}
}
설명: JSX에서는 소문자로 시작하는 이름을 HTML 태그로 인식한다. 자세한 내용은 이 문서에서 확인할 수 있다.
useEffect(function updateTitle() { document.title = name + ' ' + lastname; });useEffect(() => { title = name + ' ' + lastname; });useEffect(function updateTitle() { name + ' ' + lastname; });useEffect(function updateTitle() { title = name + ' ' + lastname; });function MyComponent(props) {
const [done, setDone] = useState(false);
return <h1>Done: {done}</h1>;
}
useEffect(() => { setDone(true); });useEffect(() => { setDone(true); }, []);useEffect(() => { setDone(true); }, [setDone]);useEffect(() => { setDone(true); }, [done, setDone]);<button onClick={this.handleClick()}>Click this</button>
<button onClick={this.handleClick.bind(handleClick)}>Click this</button><button onClick={handleClick()}>Click this</button><button onClick={this.handleClick}>Click this</button><button onclick={this.handleClick}>Click this</button>useEffect(() => {
setName('John');
}, [name]);
class Button extends React.Component {
constructor(props) {
super(props);
// 여기에 무엇이 빠졌을까?
}
handleClick() {...}
}
<React.Fragment>
<h1>Our Staff</h1>
<p>Our staff is available 9-5 to answer your questions</p>
</React.Fragment>
<...>
<h1>Our Staff</h1>
<p>Our staff is available 9-5 to answer your questions</p>
</...>
<//>
<h1>Our Staff</h1>
<p>Our staff is available 9-5 to answer your questions</p>
<///>
<>
<h1>Our Staff</h1>
<p>Our staff is available 9-5 to answer your questions</p>
</>
<Frag>
<h1>Our Staff</h1>
<p>Our staff is available 9-5 to answer your questions</p>
</Frag>
class Ticker extends React.Component {
constructor(props) {
super(props);
this.state = { count: 0 };
}
render() {
return <h1>{}</h1>;
}
}
const greeting = isLoggedIn ? <Hello /> : null;
ReactDOM.render(<Message orderNumber="16" />, document.getElementById('root'));
const element = <h1 style={ backgroundColor: "blue" }>Hi</h1>;
const element = <h1 style="backgroundColor: "blue"">Hi</h1>;const element = <h1 style=>Hi</h1>;const element = <h1 style={blue}>Hi</h1>;const element = <h1 style="blue">Hi</h1>;replaceStaterefreshStateupdateStatesetStateconst Star = ({ selected = false }) => <Icon color={selected ? 'red' : 'grey'} />;
A. <button onClick=this.handleClick>Click Me</button>
B. <button onClick={event => this.handleClick(event)}>Click Me</button>
<Route path="/:id" />
<Route path="/:id">
{' '}
<About />
</Route>
<Route path="/tid" about={Component} />
<Route path="/:id" route={About} />
<Route>
<About path="/:id" />
</Route>
const Greeting = ({ name }) => <h1>Hello {name}!</h1>;
class Greeting extends React.Component {
constructor() {
return <h1>Hello {this.props.name}!</h1>;
}
}
class Greeting extends React.Component {
<h1>Hello {this.props.name}!</h1>;
}
class Greeting extends React.Component {
render() {
return <h1>Hello {this.props.name}!</h1>;
}
}
class Greeting extends React.Component {
render({ name }) {
return <h1>Hello {name}!</h1>;
}
}
ReactDOM.render(
<h1>Hi</h1>,
document.getElementById('root')
)
<a> 태그 대신 React Router의 Link 컴포넌트를 써야 하는 이유는?<a> 태그와 동의어다<a> 태그는 React와 함께 쓰면 에러를 일으키기 때문에<a> 태그는 페이지 전체를 새로고침시키지만, Link 컴포넌트는 그렇지 않기 때문에React.createElement(x, y, z);
useEffect(() => {
// do things
}, []);
class Comp extends React.Component {
render() {
return <h1>Look at the time: {time}</h1>;
}
}
ReactDOM.createPortal(x, y);
설명: Portals
const [count, setCount] = useState(0);
설명: Hooks-State
const database = [{ data: 1 }, { data: 2 }, { data: 3 }];
database.map((user) => <h1>{user.data}</h1>);
const { name: firstName } = person;
const MyComponent = ({ names }) => (
<h1>Hello</h1>
<p>Hello again</p>
);
ReactDOM.createPortal(x, y);
<h1> 태그 안에는 무엇이 렌더링될까?const MyComponent = ({ children }) => (
<h1>{children.length}</h1>
);
...
<MyComponent>
<p>Hello</p>
<p>Goodbye</p>
</MyComponent>
const [count, setCount] = useState(0);
import React from 'react';
import { render } from 'reactjs-dom';
const element = <h1>Hi</h1>;
ReactDOM.render(element, document.getElementById('root'));
render() {
const isLoggedIn = this.state.isLoggedIn;
return (
<div>
The user is:
</div>
);
}
The user is {isLoggedIn = "no"}.The user is {isLoggedIn ? "logged in." : "not logged in"}.설명: Create React App
class StarTrekkin extends React.Component {
firePhotonTorpedoes(e) {
console.log('pew pew');
}
render() {
return; // 여기에 코드를 추가해야 한다
}
}
<button onClick={firePhotonTorpedoes()}>Pew Pew</button><button onClick={firePhotonTorpedoes}>Pew Pew</button><button onClick={this.firePhotonTorpedoes()}>Pew Pew</button><button onClick={this.firePhotonTorpedoes}>Pew Pew</button>설명: Handling Events
let dish = <h1>Mac and Cheese</h1>;
let dish = <h1 id={heading}>Mac and Cheese</h1>;let dish = <h1 id="heading">Mac and Cheese</h1>;let dish = <h1 id:"heading">Mac and Cheese</h1>;let dish = <h1 class="heading">Mac and Cheese</h1>;class Huggable extends React.Component {
hug(id) {
console.log("hugging " + id);
}
render() {
let name = "kitten";
let button = // 코드가 빠져 있다
return button;
}
}
<button onClick={(name) => this.hug(name)}>Hug Button</button>;<button onClick={this.hug(e, name)}>Hug Button</button>;<button onClick={(e) => hug(name, e)}>Hug Button</button>;<button onClick={(e) => this.hug(name, e)}>Hug Button</button>;설명: 이 문제는 클래스 컴포넌트에 대한 지식을 테스트한다. 클래스 컴포넌트에 정의된 메서드를 호출하려면 this를 사용해야 한다.
설명: 컴포넌트와 props
function Dish() {
return (
<>
<Ingredient />
<Ingredient />
</>
);
}
설명: React Developer Tools 아이콘 색상
class TransIsBeautiful extends React.Component {
constructor(props){
// 빠진 줄....
console.log(this) ;
}
...
}
constructor(props) {
super(props);
this.state = {
pokeDex: []
};
}
function add(x = 1, y = 2) {
return x + y;
}
add();

설명: Refs and the DOM
const { tree, lake } = nature;
ReactDom.render(
<Message sent=false />,
document.getElementById("root")
);
<Message sent={false} />,
ReactDom.render(<Message sent="false" />, document.getElementById('root'));
<Message sent="false" />,
ReactDom.render(<Message sent="false" />, document.getElementById('root'));