General Concepts Flashcards
Synchronous operations
are executed one at a time, and each operation must complete before the next one can start. In other words, synchronous operations block the execution of the program until they are finished.
asynchronous operations
do not block the execution of the program. Instead, they are designed to allow the program to continue executing other tasks while waiting for the asynchronous operation to complete.
purpose of a callback
to specify a function that will be executed or called at a later point in the program, often as a response to an event or the completion of an asynchronous operation.
setState what is does? is syncronic?
When you call setState, React will update the state object and trigger a re-rendering of the component, which means the component will update and reflect the new state.
The setState method in React is typically asynchronous. This means that calling setState doesn’t immediately update the state and re-render
this.state = {
counter: 0,
name: ‘John’
}; how to access to counter state?
this.state.counter holds the value of the counter, and this.state.name holds the value of the name.
when getDerivedStateFromProps is called?
getDerivedStateFromProps is a static method that is called before rendering and is invoked whenever the component is receiving new props or state updates.
getDerivedStateFromProps method for funtions?
It should be used for pure calculations based on props and state, without relying on any component-specific instance variables or methods.
can I use this in getDerivedStateFromProps?
is a static method, so you cannot access the this keyword or the component instance within this method
why getDerivedStateFromProps is static?
By making it static, it is enforced that the method does not have access to the component instance (this) and cannot modify any instance-specific data or invoke instance methods. meaning its output solely depends on the inputs and does not have any side effects.
what is a static method?
A static method in JavaScript is a method that belongs to a class itself rather than to an instance of the class.
what is a class?
a class is a template for creating objects of a particular type. It defines the properties (attributes) and behaviors (methods) that the objects instantiated from the
How to cretae an instance of this class?
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
sayHello() {
console.log(Hello, my name is ${this.name} and I am ${this.age} years old.
);
}
}
const person1 = new Person(‘John Doe’, 25);
person1.sayHello();
Which are the propertes and methos od this object?
const person = {
name: ‘John Doe’,
age: 25,
sayHello: function() {
console.log(Hello, my name is ${this.name} and I am ${this.age} years old.
);
}
};
In this example, the person object has two properties (name and age) and a method (sayHello).
is a class intance same as an object?
Yes, in the context of object-oriented programming, a class instance and an object are essentially the same thing.
what is object-oriented programming?
Object-oriented programming (OOP) is a programming paradigm that organizes code based on the concept of objects, which are instances of classes.
what is a stack
/pila?
a stack is an abstract data type that represents a collection of elements with a particular behavior known as last-in, first-out (LIFO). It is named “stack” because it resembles a stack of objects where new items are added to the top and removed from the top.
three main phases of react lifycle
mounting, updating, and unmounting.
4 methods of mounting phase
constructor()
static getDerivedStateFromProps()
render()
componentDidMount()
5 methods of Updating phase
static getDerivedStateFromProps()
shouldComponentUpdate()
render()
getSnapshotBeforeUpdate()
componentDidUpdate()
1 method of Unmounting phase
componentWillUnmount()
what are the purpose of hooks?
Hooks are a feature that allows developers to use state and other React features in functional components without the need for class components.
what is jest?
Jest is a popular JavaScript testing framework developed by Facebook.
Jest is a testing framework that provides the overall test running infrastructure. It provides functionalities such as organizing your tests into suites and test cases, providing test doubles (mocks, spies, etc.), measuring code coverage, and offering utilities for assertions. Jest does not tie you to a specific way of testing and can be used with various testing approaches and libraries.
what is enzyme?
Enzyme is a JavaScript testing utility developed by Airbnb that provides additional testing capabilities for React components. It is often used in conjunction with Jest or other testing frameworks to facilitate the testing of React components in isolation. As of September 2020, Airbnb has officially announced that Enzyme development and maintenance have been discontinued.
what is react testing library?
React Testing Library is a popular testing utility for React applications that promotes testing React components in a way that resembles how users interact with the application. It emphasizes testing components based on their rendered output and behavior rather than focusing on implementation details.
- {xxx}
- {country.name}
-
{props.name.map((--------------------) => (
-----------------------
))}
-
{props.name.map((eachm, index) => (
- {eachm} ))}