import React.Component from 'react'
import [ Component ] from 'react'
import Component from 'react'
import { Component } from 'react'
React.memo
.useReducer
.useMemo
Hook.shouldComponentUpdate
.const person =(firstName, lastName) =>
{
first: firstName,
last: lastName
}
console.log(person("Jill", "Wilson"))
return
ántes del último paréntesis.import React, {useState} from 'react';
const name = 'Rachel';
const age = 31;
const person = { name, age };
console.log(person);
{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} />
props
<Route path="/:id" />
function Dish() {
return <h1>Mac and Cheese</h1>;
}
ReactDOM.render(<Dish />, document.getElementById('root'));
div
h1
React.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.memo
React.split
React.lazy
React.fallback
useLayoutEffect
?A. <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>; }
React.PureComponent
?shouldComponentUpdate()
getDerivedStateFromProps()
es un metodo inseguro de usarconst Heading = () => {
<h1>Hello!</h1>;
};
[e.target.id]
utilizado en el código de abajo?handleChange(e) {
this.setState({ [e.target.id]: e.target.value })
}
class Clock extends React.Component {
render() {
return <h1>Look at the time: {time}</h1>;
}
}
Array.map()
?setState
en lugar de un objeto?setState
es asíncrono y podría resultar en valores no actualizados correctamente a tiempo.React
ReactDOM
Render
DOM
value
defaultValue
default
class clock extends React.Component {
render() {
return <h1>Look at the time: {this.props.time}</h1>;
}
}
this
clock
Explicación: En JSX, nombres en minúsculas son considerados elementos de HTML. Lee este artículo
useEffect(function updateTitle() { document.title = name + ' ' + lastname; });
useEffect(() => { title = name + ' ' + lastname; });
useEffect(function updateTitle() { name + ' ' + lastname; });
useEffect(function updateTitle() { title = name + ' ' + lastname; });
React.fallback
React.split
React.lazy
React.memo
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]);
handleClick
está siendo invocado en vez de estar siendo pasado como referencia. ¿Cómo arreglamos esto?<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>
fetch()
?fetch()
es provisto nativamente por la mayoría de los navegadores.useEffect(() => {
setName('John');
}, [name]);
this.setState(...)
this.forceUpdate()
class Button extends React.Component{
constructor(props) {
super(props);
// ¿Qué falta pones aquí?
}
handleClick() {...}
}
this.handleClick.bind(this);
props.bind(handleClick);
this.handleClick.bind();
this.handleClick = this.handleClick.bind(this);
<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>
count
, ¿Qué necesitas agregar dentro de las llaves en el elemento h1
?class Ticker extends React.component {
constructor(props) {
super(props);
this.state = { count: 0 };
}
render() {
return <h1>{}</h1>;
}
}
const greeting = isLoggedIn ? <Hello /> : null;
isLoggedIn
sea trueReactDOM.render(<Message orderNumber="16" />, document.getElementById('root'));
h1
pero hay un error inesperado indicando un error de token al ejecutarlo. ¿Cómo lo solucionas?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>;
replaceState
refreshState
updateState
setState
const 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
?volver
en el navegador<a>
<a>
causará errores cuando se use con React.<a>
causará un refrezco total de la página, mientras que el componente Link
no lo hará.x
, que es enviado a la función createElement
?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);
Explicación: Portals
setCount
?const [count, setCount] = useState(0);
Referencia Hooks-State
const database = [{ data: 1 }, { data: 2 }, { data: 3 }];
database.map((user) => <h1>{user.data}</h1>);
const { name: firstName } = person;
name
que el objeto firstNameconst 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(element, document.getElementById("root"));
ReactDOM(element, document.getElementById("root"));
renderDOM(element, document.getElementById("root"));
DOM(element, document.getElementById("root"));
render() {
const isLoggedIn = this.state.isLoggedIn;
return (
<div>
The user is:
</div>
);
}
The user is loggedIn ? logged in : not logged in.
The user is {isLoggedIn = "no"}.
The user is {isLoggedIn ? "logged in." : "not logged in"}.
class StarTrekkin extends React.Component {
firePhotonTorpedoes(e) {
console.log('pew pew');
}
render() {
return; // El código hay que agregarlo aquí
}
}
<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>
prop-helper
.prop-types
.checker-types
.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 = // Missing code
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>;
Explicación:
Esta pregunta testea tu conocimiento de componente de clases en react. Tenés que usar this
para llamar métodos definidos en componentes de clases.
function Dish() {
return (
<>
<Ingredient />
<Ingredient />
</>
);
}
class TransIsBeautiful extends React.Component {
constructor(props){
// Línea faltante....
console.log(this) ;
}
...
}
constructor(props) {
super(props);
this.state = {
pokeDex: []
};
}
function add(x = 1, y = 2) {
return x + y;
}
add();
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'));