Scenario Flashcards

1
Q

You’re building a shopping cart feature in an e-commerce app using Redux. How would you add an item to the cart and update the cart state?

A

To add an item to the cart and update the cart state, you would dispatch an action with the item details. The reducer would handle updating the cart state by appending the new item to the existing cart items array.

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

In a Redux-based application, how can you access the current state of the application?

A

You can access the current state of the application using the useSelector hook provided by the react-redux library. This hook allows you to select specific parts of the state based on your component’s needs.

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

You’re creating a counter component using setState in React. How would you increment the counter when a button is clicked?

A

You would define a state variable for the counter, say count, using useState. Then, in the button’s click handler, you would call setCount(prevCount => prevCount + 1) to increment the counter.

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

You’re building a form in a React component, and you want to store and manage the form data using setState. How would you handle changes in form inputs and update the state accordingly?

A

For each input element, you would set its value attribute to the corresponding state variable and handle its onChange event by calling a function that updates the state using setState with the new value.

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