What is context?

  • A JavaScript library for data visualization
  • A global object used to store application state
  • A way to pass data down to child components without using props
  • A way to pass data up to parent components without using props
Context is a way to pass data down to child components without using props. It is useful for data that needs to be accessed by many components at different levels of the component hierarchy. Context provides a way to avoid the "prop drilling" problem, where props need to be passed down through many layers of components.

How to do logging in React Native?

  • Use the console.log() function
  • Use the alert() function
  • Use the debugger statement
  • All of the above
To do logging in React Native, you can use the console.log() function, which writes messages to the console in the same way as in a web browser. You can also use other console functions, such as console.warn() and console.error(), to log warning and error messages.

Why React tab is not showing up in DevTools?

  • The React DevTools extension is not installed
  • The React app is not running in development mode
  • There is a conflict with other browser extensions
  • The React app is not using React version 16 or higher
If the React tab is not showing up in DevTools, it may be because the React app is not using React version 16 or higher. The React tab was introduced in version 16, so if you are using an earlier version of React, it will not be available in DevTools. You can check the React version in your app by looking at the package.json file or by running the command 'npm ls react'.

How to set initial state in Redux?

  • Set the initialState property in the reducer function
  • Dispatch an action to set the initial state
  • Use the createStore() function to set the initial state
  • There is no way to set the initial state in Redux
To set the initial state in Redux, you can set the initialState property in the reducer function when creating the Redux store. This allows you to set the initial state for the entire Redux store or for a specific slice of the store.

What is Redux Thunk?

  • A Redux middleware for handling asynchronous actions
  • A React component for handling forms
  • A JavaScript testing framework
  • A UI toolkit for building web applications
Redux Thunk is a middleware for Redux that allows you to write asynchronous logic that interacts with a Redux store. It enables you to dispatch asynchronous actions, such as API requests, and handle them in a synchronous way.

Is it keys should be globally unique?

  • Yes, always
  • No, never
  • It depends on the use case
In React, keys should be globally unique whenever possible. This helps React identify which items have changed, added, or removed from a list, and update the UI accordingly. While keys do not have to be globally unique in all cases, it is generally a best practice to use unique keys whenever possible.

Why do we use array destructuring (square brackets notation) in useState?

  • It's a personal preference of the developer
  • It's required by the React API
  • It's a cleaner way to write the code
  • It allows us to name the state variables
When using useState in React, the function returns an array with two elements: the state value and a function to update the state value. By using array destructuring (square brackets notation), we can name the state variables to make our code more readable and easier to maintain.

What is the recommended way for naming components?

  • Use a long name that includes the component's functionality
  • Use a name that is the same as the component's file name
  • Use a name that is the same as the component's parent folder
  • Use a simple name that describes the component
The recommended way for naming components in React is to use a simple name that describes the component. The name should be a noun or noun phrase that accurately represents the component's purpose. This makes it easier to understand and maintain the code, as well as to reuse the component in other parts of the application.

How do you access props in attribute quotes?

  • {props}
  • {someProp}
  • {this.props.someProp}
  • {this.props}
In React, you can access props in attribute quotes by using the "this.props" syntax and the name of the prop. For example, to access a prop named "someProp", you would use the syntax "{this.props.someProp}" inside the attribute quotes. This allows you to dynamically set attributes based on props, such as setting the value of an input field or the source of an image.

What is the purpose of push and replace methods of history?

  • To add or replace a new route to the history stack
  • To clear the history stack and start a new session
  • To navigate to the previous route in the history stack
  • To update the current route without adding a new entry to the history stack
The push and replace methods of the history object are used to add or replace a new route to the history stack. The push method adds a new entry to the history stack and navigates to the specified route, while the replace method updates the current entry in the history stack without adding a new one. These methods are commonly used for programmatic navigation and managing the browser history in React applications.