ReactJs Fundamentals
12 Questions
3.4 Stars

ReactJs Fundamentals

Test your knowledge of ReactJs, a popular JavaScript library for building user interfaces. This quiz covers hooks, state management, JSX syntax, and component lifecycle.

Created by

Questions and Answers

Qual é a principal vantagem do hook useState em ReactJs?

Possibilita o armazenamento de estado em componentes funcionais

O que ocorre quando você chama o método setState() em ReactJs?

O estado é mesclado com o objeto fornecido

Quais são os dois principais hooks built-in em ReactJs?

useState e useEffect

Qual é o propósito do hook useEffect em ReactJs?

<p>Adicionar efeitos colaterais em componentes funcionais</p> Signup and view all the answers

Como os componentes em ReactJs podem compartilhar seu estado?

<p>Através de props</p> Signup and view all the answers

Quais são as duas principais formas de criar componentes em ReactJs?

<p>Componentes funcionais e componentes de classe</p> Signup and view all the answers

Qual é o efeito de chamar this.setState({comments}) em um estado que contenha variáveis independentes?

<p>Ele atualiza apenas a variável <code>comments</code> e deixa as outras variáveis intactas.</p> Signup and view all the answers

Por que não se deve confiar nos valores de this.props e this.state para calcular o próximo estado?

<p>Porque eles podem ser atualizados síncrona ou assincronamente.</p> Signup and view all the answers

O que é JSX?

<p>Um syntax extension para JavaScript que permite escrever código HTML-like.</p> Signup and view all the answers

Quais são as três fases do ciclo de vida de um componente React?

<p>Mounting, updating e unmounting.</p> Signup and view all the answers

Quais métodos do ciclo de vida são chamados durante a fase de montagem?

<p>constructor, getDerivedStateFromProps, render e componentDidMount.</p> Signup and view all the answers

Qual é o objetivo do método componentWillUnmount?

<p>Para limpar recursos ou subscriptions estabelecidos durante a vida do componente.</p> Signup and view all the answers

Study Notes


ReactJs is a popular JavaScript library used for building user interfaces, primarily for single-page applications. It was developed by Facebook and is now maintained by the React community. One of the key features of ReactJs is the use of components to build and manage the application's UI, which can be both functional and class-based.


ReactJs introduced Hooks in version 16.8. Hooks allow developers to use state and other React features without writing a class, making the code cleaner and less verbose. There are two main built-in Hooks: useState and useEffect.


The useState hook is used to store state for a functional component. It accepts one parameter: initialState, which will be set as the initial stateful value, and returns two values: the stateful value and the update function to update the stateful value.


useEffect allows you to add side effects within a functional component, like after the initial render. It's not allowed within the function's main body. You can also act upon updates on the state with useEffect.

State Management

State management is crucial in ReactJs. React state is a local variable that is encapsulated within a component and is not accessible to any component other than the one that owns and sets it. A component may choose to pass its state down as props to its child components.

The setState method

When you call setState(), React merges the object you provide into the current state. For example, your state may contain several independent variables, and you can update them independently with separate setState() calls. The merging is shallow, so this.setState({comments}) leaves this.state.posts intact, but completely replaces this.state.comments.

State updates are merged

React may batch multiple setState() calls into a single update for performance. Because this.props and this.state may be updated asynchronously, you should not rely on their values for calculating the next state.

JSX Syntax

JSX is a syntax extension for JavaScript that allows you to write HTML-like code in your React components. It's a way to describe what the UI should look like and how it should behave. JSX is not a separate language; it's just a way of writing JavaScript that looks like HTML.

Component Lifecycle

A React component undergoes three different phases in its lifecycle: mounting, updating, and unmounting.

Mounting phase

In the mounting phase, a component is prepared for and actually inserted into the DOM. To get through this phase, four lifecycle methods are called: constructor, static getDerivedStateFromProps, render, and componentDidMount.

Updating phase

In the updating phase, the component updates or re-renders. This reaction is triggered when the props are updated or when the state is updated. This phase can occur multiple times.

Unmounting phase

In the unmounting phase, when the component is removed from the DOM, the componentWillUnmount lifecycle method is called to clean up any resources or subscriptions that were set up during the component's lifetime.

By understanding these concepts and focusing on the subtopics of hooks, state management, JSX syntax, and component lifecycle, developers can effectively utilize ReactJs to build dynamic and responsive user interfaces.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

More Quizzes Like This

ReactJS Overview
7 questions

ReactJS Overview

LuxuryPennywhistle avatar
React JS Quiz: Purpose, Lifecycle, and JSX
3 questions
ReactJS Features Quiz
6 questions
React Fundamentals
5 questions

React Fundamentals

FormidableWatermelonTourmaline1453 avatar
Use Quizgecko on...