React update Flashcards

1
Q

En react no es posible renderizar dos elementos juntos sin un wrapper, por eso nacio react ____ y su shortcode es <> >(angle bracket in English)

A

fragment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Usamos props.___ cuando queremos enviar varias cosas dentro y se puede usar el wrapper

A

children

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Cuando crear un componente reusable, quieres que otros lo usen bien, por eso se debe validar, con propTypes para ello se debe:

A

Incluir el proptypes JS package

En Prod no se usan, por lo que es bueno usar un plugin para removerlas

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

son string literales que permiten embedded expresiones de JS, así como usar multi lineas y interpolation

A

template literal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Dentro de las ___, siempre deben evaluar algo, devolver un valor, por eso no podemos usar for loop, if statements.

A

expresiones

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Style components with React

A
  • Se puede hacer uso de ClassName o estilos inline con style, pero se debe enviar un objeto
  • React DOM compares the element and its children to the previous one, and only applies the DOM updates necessary to bring the DOM to the desired state.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Handle events stateful function component

A

Para eventos escuchamos con onClick, onChange, etc.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Create an state using react for count

A

const [countState,setCountState] =React.useState(0)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Manejar side Effects (como llamar a APIs)

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

useEffect, called only when name is updated

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Create a custom hook called localStorateState

A

Tomar en cuenta que se empiezan con la palabra use como estandar para el linter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Para que sirven las ref en react?

A

Algunas veces toca trabajar el DOM directo por ejemplo third parties con ref o manipular video

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Pasos para crear una referencia en React

A

1- Primero se crea la referencia

const tiltRef = React.useRef();

//esto en el return()

2- luego se accede en el useEffect

const tiltNode = titlRef.current;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Qué es un lazy initializer?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

lazy initializer, what is it?

A

if you ned to use heavy function calls or access io like with localStorage, you could use lazy initializer function in useState(()=>0)

react will use it once, not in each rerender

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Some examples of side effects in React components are:

A
  • Making asynchronous API calls for data
  • Setting a subscription to an observable
  • Manually updating the DOM element
  • Updating global variables from inside a function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Explain the two useEffects

A

explain it :)

18
Q

Only Running useEffect Once

19
Q

Cleanup in useEffect

Returning a function from effect is an optional cleanup mechanism. Each effect may or may not return a function that would execute cleanup code

A

To specify the code for the cleanup, we add an anonymous return function to the component. The return function is executed every time when the component re-renders.

20
Q

Manejar forms con React hacer submit

21
Q

Tipos de forms fields

A

controlled and uncontrolled fields

22
Q

Haga un controlled field del username

A
  • El value debe apuntar al state
  • usar un onChange para actualizar el state
23
Q

Manejo de errores con React

A

Se debe crear un componente de tipo clase ErrorBoundary

  • Se crea el componente de error
  • Se agrega el fallback
  • se usa de wrapper
24
Q

Cuando se hace render de una lista, se debe tener un __ porque React usa esto para identificador único de los elementos, así cuando algo cambia, ser más eficiente a la hora de realizar el cambio en el DOM

25
Compartir state entre dos sibling components
Lo idel es mover el estado al padre más cercano de ambos
26
Los ___ proporcionan una opción de primera clase para renderizar hijos en un nodo DOM que existe por fuera de la jerarquía del DOM del componente padre.
portales
27
Caso de uso de los portales
los modals
28
Ejemplo de portal
29
Reglas de los hooks
1. No llames Hooks dentro de ciclos, condicionales o funciones anidadas 2. Llama Hooks solo en funciones de React
30
No llames Hooks dentro de ciclos, condicionales o funciones anidadas
vez de eso, usa siempre Hooks en el nivel superior de tu función en React. Siguiendo esta regla, te aseguras de que los hooks se llamen en el mismo orden cada vez que un componente se renderiza. Esto es lo que permite a React preservar correctamente el estado de los hooks entre multiples llamados a useState y useEffect.
31
No llames Hooks desde funciones JavaScript regulares. En vez de eso, puedes:
- Llama Hooks desde componentes funcionales de React. - Llama Hooks desde Hooks personalizados Siguiendo esta regla, te aseguras de que toda la lógica del estado de un componente sea claramente visible desde tu código fuente.
32
Un Hook personalizado es una función de JavaScript cuyo nombre comienza con ”\_\_\_” y que puede llamar a otros Hooks. Por ejemplo, a continuación useFriendStatus es nuestro primer Hook personalizado:
use
33
Crea un hook personalizado que diga si un amigo está online o off
34
\_\_\_ provides a way to pass data through the component tree without having to pass props down manually at every level.
Context
35
In a typical React application, data is passed top-down (parent to child) via props, but this can be cumbersome for certain types of props (e.g. **two examples**) that are required by many components within an application.
locale preference, UI theme
36
Change this to context
37
3 steps to use context
- Create context `const ThemeContext = React.createContext('light');` - wrap with provider - access the context static contextType = ThemeContext; render() { return ; }
38
Ayuda a saber cuantas veces algo se renderea y sirve para medir performance
Profiler
39
Explain useContext
Accepts a context object (the value returned from React.createContext) and returns the current context value for that context.
40
An alternative to useState. Accepts a reducer of type (state, action) =\> newState, and returns the current state paired with a dispatch method. (If you’re familiar with Redux, you already know how this works.)
useReducer
41
\_\_\_ is usually preferable to useState when you have complex state logic that involves multiple sub-values or when the next state depends on the previous one.
useReducer
42
Pasos para useReducer