diff --git a/CHANGELOG.md b/CHANGELOG.md index 1261abb..26d78ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fix useContext for uninitialized and/or changing contexts (#26) - `useMemo` now computes a new value every render if no array is provided (#29) +- Fixed `useEffect` not running when a dependency changes to nil (#32) ## [0.3.0] ### Changed diff --git a/src/init.lua b/src/init.lua index 341b2a4..14ca9a1 100644 --- a/src/init.lua +++ b/src/init.lua @@ -81,14 +81,25 @@ function Hooks.new(roact) local lastDependencies = self.effectDependencies[index] if lastDependencies ~= nil then local anythingChanged = false + local length = 0 for dependencyIndex, dependency in pairs(dependsOn) do + length += 1 + if lastDependencies[dependencyIndex] ~= dependency then anythingChanged = true break end end + for _ in pairs(lastDependencies) do + length -= 1 + end + + if length ~= 0 then + anythingChanged = true + end + if not anythingChanged then continue end