Ecommerce-Filtering-UseReducer (Practising)

SEE PREVIEW πŸ‘€

useReducer-

for self understanding

BEHIND THE SCENE OF REDUCE image

GIVE CODE A TRY πŸš€

ARRAY REDUCE METHOD image

numbers.reduce(summarize, 0) calculates the sum of all elements in the array.

The summarize callback is invoked for every item in the array with the accumulated sum and the iterated number. summarize callback adds the iterated item to the already accumulated sum, and returns that updated sum.

That's how an array is reducing to a sum.

Also, note the second argument of numbers.reduce(summarize, 0) β€” the sum of array items is initialized with 0.

What is acc here?

const numList = [1, 3, 55, 22, 44]

function oddAndEvenSumReducer(acc, value) { return acc }

oddAndEvenSumReducer=numList.reduce(oddAndEvenSumReducer)

console.log(oddAndEvenSumReducer)

so here acc is first element in array

Practice exc for useReducer

  • Find Even and Odd sum
  • Find Even and Odd sum without %2 logic
  • Cart managment πŸ’“(tried useState, then useReducer) SEE HERE
mistakes while making πŸ˜Άβ€πŸŒ«οΈ

key needs to be assigned to a jsx element

image image

useReducer should be define before return only image