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.