Skip to content

Commit

Permalink
Allows the force update to be infinitely caled
Browse files Browse the repository at this point in the history
This use case is far-fetched but in some contexts (gaming for example) the number of iterations can go beyond the maximum value supported by javascript and end up being `Infinity` which would cause the force update to stop working
because `Infinity + 1 === Infinity` is true in javascript
  • Loading branch information
zeachco committed Jun 10, 2021
1 parent eb4fb5d commit 267c3da
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/mobx-react-lite/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function useForceUpdate() {
const [, setTick] = useState(0)

const update = useCallback(() => {
setTick(tick => tick + 1)
setTick(tick => (tick < Number.MAX_SAFE_INTEGER ? tick + 1 : 0))
}, EMPTY_ARRAY)

return update
Expand Down

0 comments on commit 267c3da

Please sign in to comment.