Skip to content

Sort Function #50

Answered by CJAkkuec
mohbusaidy asked this question in Web
Aug 5, 2022 · 2 comments · 3 replies
Discussion options

You must be logged in to vote

Was @actyvystom sagt, und zudem noch:

useEffect(() => {
    if (sortProducts === 'Low to high') {
      const lth = products.price((a, b) => a - b);
      setSortProducts(lth);
    }
    if (sortProducts === 'High to low') {
      const htl = products.price((a, b) => a - b).reverse();
      setSortProducts(htl);
    }
  });

... auf den ersten Blick könntest du hier auch const htl = products.price((a, b) => b - a) schreiben.

Edit: Oh, und du solltest noch products und sortProducts als dependency für deinen useEffect hinzufügen, sonst könnte es evtl. ein bisschen arg rattern.

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@mohbusaidy
Comment options

@CJAkkuec
Comment options

@mohbusaidy
Comment options

Answer selected by CJAkkuec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Web
Labels
None yet
3 participants