question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

doesn't work with sets

See original GitHub issue
  • use-deep-compare-effect version: v1.3.0
  • node version: 12
  • yarn version: 1.21.1

Relevant code or config

const set = new Set(props.someList)

useDeepCompareEffect(() => {
  // some effects
}, [set])

What you did:

I am trying to deeply compare a Set of values but it turns out that the underlying dequal library doesnt handle Set comparison correctly.

example

var dequal = require("dequal")

let a = new Set([1,2,3,4])
let b = new Set([1,2,3,4])

console.log(dequal(a,b))

Check it running here https://runkit.com/embed/yiu9lr2kont0

What happened:

Each set is computed as different even though they should be computed as equal.

Problem description:

dequal seems to be not best library to do deep equals

Suggested solution:

We could potentially choose one of three

  • do a PR to dequal fixing this issue
  • make the comparison mechanism a parameter in useDeepCompareEffect
  • change to a more standard mechanism such as lodash’s isEqual that does compute this Set equality appropriately

hope this also helps documenting the current limitation of this otherwise awesome library.

Thanks a lot for everything and sorry to bug you (Pawn Intended)

Fran

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
kentcdoddscommented, Aug 19, 2020

🎉 This issue has been resolved in version 1.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

1reaction
kentcdoddscommented, Aug 19, 2020

Thanks @lukeed!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python sets: "in" set command not working - Stack Overflow
There are two issues here... First, it would seem like you are not testing membership at the correct depth of a nested data...
Read more >
assertEquals doesn't work for sets · Issue #2296 · cbeust/testng
assertEquals yields true if called with two sets that contain the same elements, even if they are defined as Collection . Actual behavior....
Read more >
Problem in understanding set theory - Math Stack Exchange
In set theory we not only regard the elements of a set as mathematical objects, but the sets themselves as mathematical objects, and...
Read more >
Sets in Python - Real Python
In this tutorial you'll learn how to work effectively with Python's set data type. You'll see how to ... Don't forget that set...
Read more >
Python Sets Tutorial: Set Operations & Sets vs Lists - DataCamp
The problem with nested sets is that you cannot normally have nested Python sets, as sets cannot contain mutable values, including sets. Frozensets....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found